signintech / gopdf Goto Github PK
View Code? Open in Web Editor NEWA simple library for generating PDF written in Go lang
License: MIT License
A simple library for generating PDF written in Go lang
License: MIT License
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")
}
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?
项目中有大量的不规则表格需求,有这方面的API吗?
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
Add PDF bookmarks (outlines)
How does the text wrap in the specified range?
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!
Do you think there ever would be support to add to existing PDF files? For example if you simply wanted to put some text and images on existing PDF files?
Thanks
References #17
Error happened when running go get under window 10 64bit
$ go get -u github.com/signintech/gopdf
github.com\signintech\gopdf\gopdf.go:75: undefined: zlib.HuffmanOnly
need to get zlib library before gopdf?
Do you think there ever would be support to add to existing PDF files? For example if you simply wanted to put some text and images on existing PDF files?
Thanks
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?
I found the function to change the color of the text but how can I change the color of the lines and ovals?
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
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.
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.
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.
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 'm from China, I want to use your product,But I can't use chinese. How can I get the gb2312.map or gbk.map?
this package is very wonderfull, thank you for it.
my suggestion just like title.
I wish it can support this.
Create page how to implement 90 ° flip?
When imported pictures, how to use [] byte
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.
希望能有添加书签的功能 Want to add a bookmark
Can I measure the string length that I want draw ?
How can I cordinate the text precisely ?
thanks !
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..)
How can I draw rectangle, filled by custom color?
Enable setting of Author, Title, Etc...
is gopdf support HTML and CSS3?
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.
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!
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!
PDF documents are able to contain and run javascript. Is there any way to do this in this library?
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")
}
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.
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)
Use gopdf.Config.Unit to control measuring units.
#38
How do we deal with text wrap issue in gopdf? Should we manually measure the width of the text?
if i set pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 2480, H: 3508}}) ,
is this setting for A4 page?
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")
}
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.
Hello, I use this library will be converted to Chinese characters PDF many words are not, can solve this problem?
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.
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.
Can it add read data function ?
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?
Are there any plans to support digital signature fields?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.