Git Product home page Git Product logo

gopdf's People

Contributors

adrien3d avatar akhll avatar alekskukoba avatar balacode avatar captaincodeman avatar chetanyakan avatar douglasm avatar evilsocket avatar fung-leung avatar futjikato avatar hiketsu avatar kebhr avatar liuben avatar lstrihic avatar mboonchai avatar micrococonut avatar miiton avatar mikamiel avatar nmaupu avatar oneplus1000 avatar praeto avatar raff avatar solairw avatar tao-s avatar toshiya-doi avatar tr1sm0s1n avatar ubavic avatar vingarcia avatar xoviat avatar zhaori96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gopdf's Issues

More of a question...

I currently have an existing pdf that needs to be converted to a PDF/A and exposed via an endpoint. Is it possible to save to that format here?

fine dotted line looks like a dashed line.

Im testing out your library. When I draw a thin line that is "dotted" they look like dashes, i.e.:

package main

import (

	"github.com/signintech/gopdf"
)

func main() {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{
		Unit: "pt",
		PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
	pdf.AddPage()

	x := 30.0
	y := 30.0
	size := 25.0
	halfSize := size/2
	pdf.SetLineWidth(0.1)
	pdf.SetLineType("dotted")
	pdf.Line(x, y, x+size, y+size)
	pdf.Line(x+size, y, x, y+size)

	pdf.SetLineWidth(0.1)
	pdf.SetLineType("solid")
	pdf.Line(x+halfSize, y, x+halfSize, y+size)
	pdf.Line(x, y+halfSize, x+size, y+halfSize)

	pdf.SetLineType("solid")
	pdf.SetLineWidth(0.5)
	pdf.Line(x, y, x+size, y)
	pdf.Line(x, y, x, y+size)
	pdf.Line(x+size, y+size, x+size, y)
	pdf.Line(x+size, y+size, x, y+size)

	pdf.WritePdf("line.pdf")
}

Text wrap

How do we deal with text wrap issue in gopdf? Should we manually measure the width of the text?

can not print chinese character "张"

I use your library for generating PDF,but it can not print chinese character "张",other chinese characters can print,why?
I refer to your sample code,and add the chinese font wts11.ttf.
pdf.AddTTFFont("HDZB_5", "../ttf/wts11.ttf") pdf.SetFont("HDZB_5", "", 14)

Render PDF

Can I render PDF on server (render output) not write to disk,

In TCPDF (PHP) it has output method
$pdf->Output('title.pdf', 'I');

Can I do the same thing?

Failed to go get

Error happened when running go get under window 10 64bit

$ go get -u github.com/signintech/gopdf

github.com/signintech/gopdf

github.com\signintech\gopdf\gopdf.go:75: undefined: zlib.HuffmanOnly

need to get zlib library before gopdf?

Error in example code

In the example code, please replace the line
/var/www/fpdf17/output/x.pdf with x.pdf because by default that location may not be accessible to write.

Adding a second image, seems to still print the first image

Hi,

I've got some code that prints a row of the same images. I then print another row of another image - but that other row, although it takes the size of the correct image, the image it actually prints is the first image used.

Here's the code snippet:

                    for c := 0; c < x; c++ {
                            pdf.Image("./lm2.jpg", float64(10+(c*50)), pdf.GetY()+25, nil)

                    }
                    for d := 0; d < y; d++ {
                            pdf.Image("./lm3.jpg", float64(10+(d*50)), pdf.GetY()+65, nil)
                    }

It works exactly as it should - only the second line contains whatever image is loaded in the first line.

Any ideas what I'm doing wrong?

Thanks in advance!

Draw image over rectangle

I am trying to insert an image on top of a rectangle without much success.

pdf.SetFillColor(37, 45, 66)
pdf.RectFromLowerLeftWithStyle(X, Y+H, W, H, "F")

bytesOfImg := GetImageBytesFromOutThere()
imgH, _ := gopdf.ImageHolderByBytes(bytesOfImg)
imgRect := gopdf.Rect{
	W: 200,
	H: 300,
}
pdf.ImageByHolder(imgH, x, y, &imgRect)

No matter what I try the picture is drawn under the rectangle.

layer

PNG image support

Hello!

I followed the image embedding example and found that it only works with JPG images.

With PNG, the generated PDF doesn't show the image. The PDF is about the right size, so it must have read it in.

A4

if i set pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 2480, H: 3508}}) ,
is this setting for A4 page?

Question: Cell fill color

I am trying to figure out a way to set the fill color of a cell, much like the way you would draw a filled rectangle.

pdf.RectFromUpperLeftWithStyle(x, y, 200.28, 150.89, "FD")

Thus far, I have not seen a way to do this. I want to build a PDF with tabular data, and need to be able to fill the cell background with a certain color. As far as I can tell, I'm stuck with a white background for cells.

Support for non-ASCII text

I tried putting non-ASCII text in a PDF by simply modifying the example, and use

pdf.Cell(nil, "ÁÉÍÓÖŐÚÜŰ")

instead of

pdf.Cell(nil, "Hello, world")

but nothing is visible. I used Roboto-Regular.ttf for my test from google fonts, which is known to have these characters.

Interestingly the text is not visible in the PDF (checked with Foxit Reader and Adobe Acrobat Reader DC), but the text is somehow there. It can be selected with the text tool and copied to the clipboard.

add compression of content streams

Kind of a feature request :)

Added compression to all content streams (not very fluent in go, changes have been based on PdfDictionaryObj.build; "works for me")

Should never create an invalid PDF (/FlateDecode Filter will be applied before interpreting content). Size of compressed content stream could be bigger than uncompressed stream for very small streams, or for streams with high-entropy content. But compression will work in most cases.

Text-rich documents should profit most, as PDF Unicode-Encoding (hex-encoded UCS16) is rather verbose and should compressed comparatively well.

Maybe this should be made into an document-level option, so that compression can be turned off if needed?

Pull Request: #59

Thank you!

Javascript

PDF documents are able to contain and run javascript. Is there any way to do this in this library?

MeasureTextWidth befor pdf.Cell caused char not found Error

w, err := pdf.MeasureTextWidth("志村正信")

caused char not found Error

but

pdf.Cell(nil, "志村正信")
w, err := pdf.MeasureTextWidth("志村正信")

passed without error

fyi

pdf.Curr.Font_ISubset.AddChars("志村正信")
w, err := pdf.MeasureTextWidth("志村正信")

also passed without error
I used this for workaround

support for bold font style

If I embed both font of bold and normal, the size of PDF will larger than only embed one font.
I want to embed one font only to shrink file size and get bold and normal font style by code.
Currently the package only support "" and "U" font style, could you support bold font style or tell me how can I do to make a pr.
ps: the project is awesome! you've done a great work!

Generated PDFs won't print with cups-pdf

Great package, but I'm having a small issue.
PDFs I create print fine when going through Adobe reader, but when trying to print them from the command line using the "lp" command the job immediately stops. The cups error log show that the PDF is missing the "startxref" section of the trailer. I checked it out in a hex editor and cups isn't lying. It's not there. I took a look at the code that is generating the trailer and it didn't look too hard to add it. Tested that fix and it works for me, so if you want to take a look I can open a PR or just send you a patch file. Whichever you prefer.

SVG support

Hi,

Thank you in advance for such a great library.

I was trying to add an SVG image to a generated file and I had no success so far. Is that format supported? If not, is there any possibility to add support to it? I need it because I am required to print high quality copies of the pdf.

Alternative ways to add a font

Hi, it would be really nice if we can add a font from []byte (or io.Reader), so fonts can be embeded directly into the binary (via go-bindata etc..)

Different file hashes with same content

I generate files twice with same content, but the file md5 hashes are different
I want to use md5 to verify the content has not been modified, Is there any way to acheive this?

All units are measured in pt instead of mm

I have the following code snippet:

pdf.Start(gopdf.Config{Unit: "mm", PageSize: gopdf.Rect{W: 210, H: 297}})
...
pdf.RectFromUpperLeftWithStyle(100, 100, 100, 100, "F")

Somehow the unit config is ignored and everything is calculated using pt instead of mm.

Kerning support feature request

Hi, gopdf developers, thanks for a nice native package. The only feature i miss is kerning support. Without kerning, generated pdf documents look non-professional. It's a weak point of almost all open source pdf libraries. Do you have plans to implement this at some point?
Especially it would be great if one could add/override internal font kerning values for arbitrary character pairs because many fonts lack thorough kerning spacings.

An issue with precisely aligning characters over a baseline

Hi, oneplus1000,
I've encountered a problem when aligning characters of different sizes/typefaces over a same baseline. Characters do not position accurately.
Is there a way to precisely put arbitrary characters(of arbitrary sizes/typefaces) over a same baseline?
Maybe I'm doing something wrong? Is TypoAscender() the right metric in this case?

import (
    "github.com/signintech/gopdf"
    "github.com/signintech/gopdf/fontmaker/core"
)

func getSpecTypoAsc(fontPath string, fontSize float64) float64 {
    var parser core.TTFParser
    parser.Parse(fontPath)
    typoAsc := float64(parser.TypoAscender()) * 1000.00 / float64(parser.UnitsPerEm())
    return typoAsc * fontSize / 1000.0
}

func main() {
    arialPath := "./ttf/arial.ttf"
    dejavuPath := "./ttf/DejaVuSerif.ttf"
    pdf := gopdf.GoPdf{}
    pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
    pdf.AddPage()
    pdf.AddTTFFont("arial", arialPath)
    pdf.AddTTFFont("deja", dejavuPath)
    pdf.SetX(0) 
    pdf.SetY(0)
    pdf.SetFont("arial", "", 60)
    pdf.Cell(nil, "h")
    pdf.SetFont("arial", "", 30)
    pdf.SetY(getSpecTypoAsc(arialPath, 60) - getSpecTypoAsc(arialPath, 30))
    pdf.Cell(nil, "h")
    pdf.SetFont("deja", "", 20)
    pdf.SetY(getSpecTypoAsc(arialPath, 60) - getSpecTypoAsc(dejavuPath, 20))
    pdf.Cell(nil, "h")      
    pdf.WritePdf("baseline.pdf")
}

baseline-dif

Adobe Acrobat Error

When I try to open a generated pdf in Adobe Acrobat I get the following error.

There was an error processing a page. There was a problem reading this document (135).

I can pm the offending document.

invalid xref created

mupdf, xpdf (open source pdf viewers) complain about an invalid xref table, but they can fix the problem.
PDF-specification states that the "end of line" marker must be two characters wide.

That I can fix myself :)
Pull request: #57

Line and oval color

I found the function to change the color of the text but how can I change the color of the lines and ovals?

License?

Thanks for this lib, it works quite well :)

Could you add a license to the code? Preferrably MIT or some BSD one. I'd like to use this in a project but cant if theres no license file in the repo.

Thanks in advance!

I can not use Arabic language in pdf

hi Great work but

I want to use the library gopdf
But it does not support the Arabic
I want solve the problem

package main
import (
"log"
"github.com/signintech/gopdf"
)
func main() {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{ PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4
pdf.AddPage()
err := pdf.AddTTFFont("HDZB_5", "./ttf/zahra.ttf")
if err != nil {
log.Print(err.Error())
return
}

err = pdf.SetFont("HDZB_5", "", 14)
if err != nil {
log.Print(err.Error())
return
}
pdf.Cell(nil, "هُنَالِكَ دَعَا زَكَرِيَّا رَبَّهُ قَالَ رَبِّ هَبْ لِي مِنْ لَدُنْكَ ذُرِّيَّةً طَيِّبَةً إِنَّكَ سَمِيعُ الدُّعَاءِ")
pdf.WritePdf("test1.pdf")
}

8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.