[GNC] [GNC-dev] PDF Reports

Michael Hendry hendry.michael at gmail.com
Thu Mar 19 11:43:13 EDT 2020


> On 19 Mar 2020, at 13:29, Adrien Monteleone <adrien.monteleone at lusfiber.net> wrote:
> 
> Michael,
> 
> Out of curiosity, does the built-in print to file (as PDF) or ‘Make PDF' features of GnuCash not produce a proper document for you?

"Print => Print to File" fails - “Operation not supported”.
"Make pdf" succeeds, but generates a horizontally split row of characters across page breaks, like this:

https://www.dropbox.com/s/t345r4ex4wfmjgb/Screenshot%202020-03-19%2015.12.47.png?dl=0

“Print ==> a selected printer” appears to bypass the Mac’s own printer drivers, and produces the same horizontally split lines across page breaks.

> 
> Does opening the HTML in a browser or other app not create a proper document when saving to PDF via the MacOS print facility?

That works fine, as does Safari’s "File => Export as PDF…”.

My conclusion is that the problem arises when GnuCash is dealing with the pagination. When it is creating an HTML file it doesn’t have to bother with that aspect, which is dealt with by the browser.

I chose to go down the shell script route so as to avoid having to (remember to) open each HTML file in Safari and export to PDF every time I made a change in a report and exported it to HTML.

> 
> Also, for anyone investigating this, two additional excellent utilities are `html2pdf` or `wkhtmlpdf`.

Agreed, “htmldoc” is probably a sledgehammer for this particular nut, but it was the first open-source utility I came across.

Regards,

Michael

> 
> Regards,
> Adrien
> 
>> On Mar 19, 2020 w12d79, at 3:28 AM, Michael Hendry <hendry.michael at gmail.com> wrote:
>> 
>> Morning, Alan.
>> 
>> I’m currently working through a series of reports which _will_ need to be examined by an auditor, and have been refining the reports’ configuration settings as I go.
>> 
>> To ensure that I’ve converted all the HTML files to PDF, I’ve written the shell script below which may be helpful to other Mac users as it stands, or for other OSes with appropriate modification.
>> 
>> Regards,
>> 
>> Michael
>> 
>> 
>> #!/bin/sh
>> # h2p.sh
>> #
>> # Michael Hendry
>> # 19th March 2020
>> #
>> # Convert all .html files in current directory to .pdf files in subdirectory ./pdf (created if necessary)
>> #
>> # Requires “htmldoc” - see https://formulae.brew.sh/formula/htmldoc
>> #
>> # First make a directory for the converted files (the -p means it will create the whole path if necessary)
>> mkdir -p ./pdf
>> # Now loop through all .html files and convert to pdf
>> for f in *.html
>> do # Note that $f has to be enclosed in quotation marks, to cope with spaces in filenames.
>> 	txt=${f%.*}
>> 	htmldoc --charset utf-8 --webpage --header ... -f  ./pdf/"$txt".pdf "$f"
>> done
>> #
>> # Alternatively, the following command con be run from the command-line:
>> #
>> # mkdir -p ./pdf ;for f in *.html;do txt=${f%.*}; htmldoc --charset utf-8 --webpage --header ... -f  ./pdf/"$txt".pdf "$f" ;done
> 
> 
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> If you are using Nabble or Gmane, please see https://wiki.gnucash.org/wiki/Mailing_Lists for more information.





More information about the gnucash-user mailing list