
Gofpdf: Generate PDFs from Go with No Dependencies - ingve
https://github.com/jung-kurt/gofpdf#gofpdf
======
spyspy
We use this to generate the NYTimes Crossword PDFs. I'd say the API is a
little wonky (there are several different methods just for writing text) but
it gets the job done. I wish it supported font compression though. We have to
pipe the PDFs through ghostscript to get them back to a reasonable size.

~~~
voltagex_
Can your employer sponsor a developer to implement compression?

~~~
barsonme
or just do it in your free time to give back! some of my favorite personal
projects (like my decimal library) were things i might've been able to justify
doing at work, but decided to explore on my own time.

~~~
voltagex_
Nah, open source needs funding.

~~~
baby
I don't think Newspapers have a lot of money to give away these days.

------
Scorpiion
It's also worth noting that Chrome headless could be a nice alternative if you
use html as the base for say invoices or reports that you want to generate
from a SaaS app.

Create pdf with Chrome headless: chrome --headless --disable-gpu --print-to-
pdf [https://www.chromestatus.com/](https://www.chromestatus.com/)

Source:
[https://developers.google.com/web/updates/2017/04/headless-c...](https://developers.google.com/web/updates/2017/04/headless-
chrome#create_a_pdf_dom)

~~~
nurettin
Disable GPU because they assume headless servers don't have graphics cards
installed ?

~~~
sannee
You would also probably need to have DISPLAY pointing to an X server (to get
OpenGL), which is somewhat cumbersome for daemons to do.

------
JelteF
Luckily I haven't had the need to create pdfs yet now that I'm using Go.
However, if I would, I would generate LaTeX instead of PDFs directly. I did
the same in Python a and it has turned out great:
[https://github.com/JelteF/PyLaTeX](https://github.com/JelteF/PyLaTeX)

The API can be made much more high level, because of all functionality and
packages LaTeX has. The most important thing is to have a good escape function
that is used by default for all text, otherwise it's very easy to execute
arbitrary shell commands for an attacker. If anyone wants to create a Go
package similar to mine, feel free to contact me if you want any more advice
(email in github profile).

~~~
nine_k
That "no dependencies" thing is important sometimes. Latex is a large
dependency.

~~~
JelteF
I agree that sometimes not having dependencies is important and that's
definitely a big feature of this library. However, in my experience it is more
desirable in many cases to have clear code. You basically get this for free
when by using LaTeX, because you create documents at a higher level than
writing raw pdfs. Another big advantage ia that you can make use of its vast
package ecosystem, which allows you to for instance create beautiful tables
that span multiple pages with ease.

It definitely is a large, and more importantly external, dependency though.
However, if you control the installation environment of your software this
isn't really a problem. For all use cases where I had to generate pdfs this
was the case (webapps and local one off scripts).

~~~
simooooo
I agree. No dependencies is nice, but you step into a myre of dealing with low
level pdf faffery. I'd rather let a very robust external tool with proven
reliability

------
mixedCase
I recently used this to create a language agnostic tool that generates reports
in an unified format for two different services.

Can't say it's completely painless due to the imperative nature of the API but
it served me well. If you're reading this, thank you maintainers!

~~~
swah
Do you what one would use to generate professional looking report PDFs?

~~~
osrec
The quality of the report depends significantly on the designer. I've seen
some very good looking documents generated client side with pdfmake
(JavaScript). In my SaaS product (link in profile), we generate PDF invoices
with it, and they look very professional. It's a bit painful to get things
typeset correctly, but once you have it right, the documents look great.
pdfmake is a good option if you don't want to load your server CPUs up with
generating PDFs...

------
ajstarks
I used this library to build the PDF client[1] for the deck [2] Go package.
Here are some examples [3, 4, 5]

[1] [https://github.com/ajstarks/deck/](https://github.com/ajstarks/deck/)

[2]
[https://github.com/ajstarks/deck/tree/master/cmd/pdfdeck](https://github.com/ajstarks/deck/tree/master/cmd/pdfdeck)

[3] [https://speakerdeck.com/ajstarks/the-other-side-of-go-
progra...](https://speakerdeck.com/ajstarks/the-other-side-of-go-programming-
pictures)

[4] [https://speakerdeck.com/ajstarks/a-view-of-design-and-
user-e...](https://speakerdeck.com/ajstarks/a-view-of-design-and-user-
experience-designing-for-people)

~~~
teknico
Thank you so much for Deck! I used it for a few talks recently, you can find
two of them about Go on my BitBucket page:
[https://bitbucket.org/teknico/](https://bitbucket.org/teknico/) You also have
a pull request on Github. :-)

------
tyingq
A mostly straight port from PHP to Go is pretty interesting. Nice to see PHP
libraries get a little love here and there.

------
JeanMarcS
I've used fpdf years ago to make invoices on websites. I really like this
library and it's cool to have it in Go.

It's not just a HTML to PDF library, it lets you make very precise stuff, and
it was very useful back in the day.

