Generating PDF invoices with Go and UniDoc
Updated: Oct 13, 2020
Creating good-looking PDF invoices from your application tends up to be tedious most of the time. You need to deal with different layouts, design, text-positioning, etc., and that's something most software developers want to avoid.
The most common approach to building PDF files, including invoices, is having an HTML template, filling it up with data, and then converting it to PDF. When converting HTML to PDF, most tools have issues with the PDF layout: margins, page breaks, and text positioning.
By using UniDoc, a comprehensive Golang PDF Library, you'll be creating beautiful PDF invoices from your Go application with only a few lines of code. The example below creates a simple PDF invoice for Jane Doe, containing five products, notes, logo and pricing details.
Upon execution, the following PDF file will be generated:
You can download the PDF file from the above example here.
The above example demonstrated creating a simple PDF invoice. A very similar example is available as a test file here.
The generated invoice is highly customizable. Things like text formatting (font, color, size), page styling and size are easily changeable.
The following function manipulates various parts of the invoice:
The code for manipulating invoice styling could be done in createInvoice func as well. Upon execution, following invoice is generated:
Thus, customized invoice generation is quite easy to do with UniDoc. If you have any further requirements please raise an issue on UniDoc's GitHub repository and we will gladly assist you with it.