jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.34k stars 786 forks source link

Can i get a tutorial of how to make a complex PDF like the one below? #136

Open chalkedgoose opened 7 years ago

chalkedgoose commented 7 years ago

http://www.independentagent.com/Education/VU/SiteAssets/Documents/PDF/ACORD/ACORD27EvidenceOfPropertyInsurance.pdf

jung-kurt commented 7 years ago

Another link

This can be done. I've been meaning to write an example that demonstrates my way of doing a boxed form like this. In a nutshell, you want to tabulate the coordinates of each box and drive the PDF generation from data rather than code. For example, declare a struct type that contains the coordinates (left, top, right, bottom) and other fields such as header or text contents. Define a slice of these structs populated with the appropriate values. Write a function that is called for each element. Don't worry about drawing lines over lines (for example, the left line of one box overwriting the right line of the previous box) -- the drawing is exact and the overdrawing will have no effect. Within that function, do the right thing based on the field value. For example, a zero value for the header string means to not write the header.

The trick is to measure everything in advance, and to minimize your code by putting as much detail into your data structure.