7 ms·
Gofpdf: Generate PDFs from Go with No Dependencies
- mixedCase 9y agoI 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 9y agoDo you what one would use to generate professional looking report PDFs?
- anonfunction 9y agoIt's not a Go program but Microsoft Office or Apple's equivalent can make "professional looking" reports you can export to PDF. You could also use Photoshop if you want to be more creative or LaTeX if you're going for a minimalistic look.
- swah 9y agoI meant programmatically customizable "reports" like invoices with charts. Sorry I didn't mention.
- mappu 9y agoShell out to wkhtmltopdf.
- nyir 9y agoJust to say, we did this and it looks pretty good, most importantly though the templates including any JS if necessary makes this _very_ easy for designers to work with on their own. Downside is that the browser is pretty old.
- osrec 9y agoThe 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...
- deleted 9y ago[deleted]
- mixedCase 9y agoThis worked quite fine and the output is more than satisfactory. We were looking to replace both a slow interpreted PDF renderer and a Webkit-based solution, the first one not up to our standards and the second one too much of a security gamble for the nature of the project. I wouldn't recommend it however if your design is complex, you're on a very tight schedule and you can stomach Webkit. Truth is Gofpdf requires careful coding and testing to make sure you're drawing things in the right places. You draw using simple primitives positioned around the page with a "cursor"; not something that lends itself to pumping out flashy results in little time.
- nathan_f77 9y agoYour second paragraph is exactly why I built FormAPI [1]. We have a UI to position form fields, so you don't have to do everything in a text editor. (We also have an HTML/CSS editor to create your own templates.) [1] https://formapi.io/templates/mr4ekGhgZTptdQaN/edit https://formapi.io/templates/mr4ekGhgZTptdQaN/edit
- JelteF 9y agoLatex is very easy to generate from any programming language, because it's just text. I created a Python package for it with an easy and extensible API: https://github.com/JelteF/PyLaTeX https://github.com/JelteF/PyLaTeX If you want to create something similar, be sure to escape untrusted input though. With an escape function similar to the one in my library. Otherwise it's very easy for an attacker to execute arbitrary commands.
- exhilaration 9y agoWe're mostly web developers so we designed our complex shipping invoices in HTML and ran them through DocRaptor's API https://docraptor.com https://docraptor.com for many years with beautiful results at a reasonable cost. Eventually other teams in our organization started doing the same so we paid a few thousand bucks for the package DocRaptor uses in the backend https://www.princexml.com https://www.princexml.com and run it locally.
- nathan_f77 9y agoI've built a SaaS service that generates PDFs, and I've just added an HTML/CSS editor for this purpose [1]. It uses Liquid templates and SASS. After you set up all of the fields, you can just post data to a simple API. We also provide an online form that people can fill out. If you just need to post your own HTML/CSS and get a PDF, then I'd recommend DocRaptor [2]. [1] https://formapi.io/templates/tpl_mFAsZEmhCtG9FX5N/edit https://formapi.io/templates/tpl_mFAsZEmhCtG9FX5N/edit [2] https://docraptor.com https://docraptor.com
- tyingq 9y agoA mostly straight port from PHP to Go is pretty interesting. Nice to see PHP libraries get a little love here and there.
- JelteF 9y agoLuckily 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 9y agoThat "no dependencies" thing is important sometimes. Latex is a large dependency.
- JelteF 9y agoI 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 9y agoI 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
- kibibu 9y agoThat is a large understatement. TexLive is like 4GB
- ajstarks 9y agoI 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-programming-pictures https://speakerdeck.com/ajstarks/the-other-side-of-go-progra... [4] https://speakerdeck.com/ajstarks/a-view-of-design-and-user-experience-designing-for-people https://speakerdeck.com/ajstarks/a-view-of-design-and-user-e...
- teknico 9y agoThank 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. :-)
- spyspy 9y agoWe 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_ 9y agoCan your employer sponsor a developer to implement compression?
- barsonme 9y agoor 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_ 9y agoNah, open source needs funding.
- baby 9y agoI don't think Newspapers have a lot of money to give away these days.
- pjmlp 9y agoSupermarket lady doesn't take pull requests.
- 59nadir 9y agoRarely do companies do things from the goodness of their hearts, simply because it would be nice for other people. I don't see why anyone would do it for them. If they want a feature they should get it done themselves.
- frik 9y ago
- Proven 9y agoGo is always with no dependencies, wtf...
- Scorpiion 9y agoIt'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-chrome#create_a_pdf_dom https://developers.google.com/web/updates/2017/04/headless-c...
- laktek 9y agoIf you are looking for a hosted API on top of Chrome headless, I built https://pdf.cool https://pdf.cool
- nurettin 9y agoDisable GPU because they assume headless servers don't have graphics cards installed ?
- sannee 9y agoYou would also probably need to have DISPLAY pointing to an X server (to get OpenGL), which is somewhat cumbersome for daemons to do.
- JeanMarcS 9y agoI'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.