Create Beautiful PDFs From Your Tinderbox Documents

I want to use Tinderbox to create structured documents, and then export them to beautiful PDFs.

tinderbox-to-pdf_v0_1_0.tbx (102.4 KB) is a document I created to do this. Here is the generated PDF.

It uses Pandoc to convert Tinderbox’s exported HTML to a PDF via LaTeX. Setup instructions are explained in the Tinderbox document.


I’ll push small updates to the GitHub project and update this post whenever I release a new version.

9 Likes

Nice work @Pat. Clever, well conceived and executed – and definitely worth the significant effort you obviously put into it. For longer, complex documents your approach will help a lot of readers.

Thank you!!! :raised_hands: :raised_hands: :raised_hands:

I didn’t test this – but since you are using LaTeX for its PDF parser, would your export technique render LaTeX code when our notes contain it?

I would suggest for ease of maintenance and readability, that you consider using a code note and the techniques that Mark Anderson explains here rather than putting the whole text of your Big Rule into the $Rule box in the Action Inspector. That control does not scroll, and reading a rule whose size exceeds the text box is cumbersome.

An alternative to @Pat’s process is to use the Marked 2 application. Pat’s example TBX can be exported to HTML and that .html export document can be dragged into Marked 2 for rendering and saving as PDF. Just another approach for those less technically inclined.

For anyone interested in Tinderbox history, a trip to the legacy forum will reveal some earlier approaches to PDF exporting. YMMV, since that forum covers versions of Tinderbox that might operate differently than v7.

1 Like

Pandoc seems to ignore LaTeX commands in the exported HTML. I suspect there’s some way to get them to work, I just haven’t explored it yet.

Cool, I haven’t used code notes yet, so I’ll check that out :+1:

Sort of. One feature that’s important to me is a table of contents. I want a clickable table of contents at the beginning of the PDF, and I want Preview.app to correctly show a structured table of contents as well. Marked 2 does not support intra-document links, so the clickable table of contents is a no-go with that.

You’re absolutely right though, there are a number of programs to convert Markdown to PDF that are a lot simpler than this setup. If I find one that does what I want, I’ll probably ditch this :slight_smile:

(plus I know that this approach has its own tradeoffs that I’ll have to deal with)

FWIW, the PDF version of the Tinderbox Help that I help create uses export of styles CSS (including print media CSS) and wkhtmltopdf to generate a PDF with a ToC from the HTML. As the source TBX’s primary role is to generate the HTML needed for the app’s Help, the export to HTML for PDF use is done as a parallel and separate process.

For my part, I insert Latex code directly into my notes, copy and paste it into a Latex editor and Bob’s your uncle (Le tour est joué, in French)!

I haven’t seen the PDF help, only the built-in Mac help (which I think is based off of HTML).

Are you able to share that setup? I’ve used wkhtmltopdf in the past but it always results in tiny text and huge margins. I’d love an HTML-to-PDF method that’s more faithful to the original HTML styling.

Yes, Tinderbox’s Mac Help (as via app’s Help menu) uses HTML (Mac Help’s inner format) which is generated from a (non-public) TBX file.

The PDF can be accessed here: http://www.eastgate.com/download/tbxman720.pdf

wkhtmltopdf v12.4 fixes a number of useful things but has a regression error causing font size issues, so a bit of experimentation is needed to get the correct output font size. The command lines are here.

CSS: the 'manual.css used for the styling of the primary (Help) output (here), then print.css and screen.css (here and here) used only by the for-PDF export.

Okay! Thank you for that. So does the HTML that’s fed into wkhtmltopdf get manual.css + print.css + screen.css ?

Sorry, see here. This page is exported when the TBX exports to HTML but is essentially separate resource. The sed command in the above linked text file is necessary to set in-page links to work correctly (i.e. what were in-doc links in the TBX). If you want access to the Help TBX please contact Eastgate directly as it’s not mine to share.

HTH :slight_smile:

1 Like

It does, thank you!!

Thanks a lot, Mark Anderson.
Might I ask you some questions?

I try to make PDF export using wkthmltopdf ( ver.0.12.4 ) under MacOSX10.11.6 ElCapitan via Terminal.app.

I renamed your print-export-source.html to index.html.
Then my command lines are like under.

wkhtmltopdf --page-size “Letter” --dpi 765 --footer-spacing 4 --print-media-type --footer-center “[page] of [topage]” --footer-font-name “Helvetica Neue” --footer-font-size 11 --footer-line --footer-spacing 5 --header-spacing 5 --header-line --header-center “Tinderbox v7 Manual” --header-font-name “Helvetica Neue” --enable-toc-back-links toc --toc-header-text “Tinderbox v7 Manual - Table of Contents” --toc-text-size-shrink 1 --toc-level-indentation 4em “index.html” “output.pdf”

I get output.pdf almost same as tbxman720.pdf,
( I do not care without graphical contents),
but linking from index to textual explication,
do not work.

How and where should I set your css files in command lines
which put down with print.css screen.css manual.css?

wkhtmltopdf --user-style-sheet print.css screen.css manual.css --page-size “Letter” --dpi 765 --footer-spacing 4 …etc… --toc-header-text “Tinderbox v7 Manual - Table of Contents” --toc-text-size-shrink 1 --toc-level-indentation 4em “index.html” “output.pdf” ??

Is this forms of writing ill-written or crop up ?

Or should I use different kind of command lines?

Yesterday, I got a HELP.tbx from Mr.Mark Bernstein.
I do not know how to make linking from this HELP.TBX to css files.

I look forward to hearing criticize constructively
from you at your earliest convenience.

Thx and regards, WAKAMATSU kunimitsu

I think the problem is that you need to run the sed command line - in the same text file as the wkhtmltopdf command I linked to above. Export the single page HTML, run the sed command line on the HTML page before using wkhtmltopdf.

Why? Because Tinderbox export isn’t designed to export in-page links (i.e. links to #anchors in the same page). My templates produce part of the code, but the regular expression changes, done via sed is needed to complete the task. After the sed command has been run the in-document links will work in HTML and are thus correctly embedded in the PDF at the next stage.

I’m sorry there’s currently no detailed description of this, it was simply something I knocked up to Help Eastgate provide help in PDF form as some users were demanding.

The CSS files are produced as an export from notes in the TBX just like the HTML - look at the TBX and the export seetting for those notes. How the HTML links to CSS is absolutely normal HTML coding. If not sure on this, I’d would look look at:

  1. a basic HTML tutorial on how to write an HTML file that uses an external CSS file.
  2. the Help.tbx’s export templates
  3. a CSS tutorial in the @ directives for defining CSS styles to be used only for certain forms of media (e.g. screen vs. print).

Does this help?

Dear Mark Anderson,

Thanks a lot for your point out.

I will make a thorough review of the points put forth by sed command.

I can find many notes with Outline view.

In Tinderbox HELP.tbx, there is a css note.
Can not I use and rewrite adding with your css files ??
But, unfortunately, I am not in a position to go any further.

And Export note have three type of Template [/Templates/page template children list]

  1. Simple Export [/Templates/page template]
  2. Exporting to HTML
    and
  3. Export Templates (Designators, Placeholders, Macros and Group Designators)
    [/Templates/page template children HTML item]

On the other hand, there are plain notes
i ) Templates [plain]
ii ) css [plain]
etc.

I wish I could find informations about how to add [css ]in Template.
How the HTML links to CSS not come to my hand, yet even in whole HELP.tbx.

Should I need to make a folder as a [Templates] , first ?

I have nothing good to report t the moment.

I will put [sed command] in action during this afternoon.

I will present a report on it, later.

I owe you a great debt of gratitude.

Thx and regards, WAKAMATSU kunimitsu

Dear Mark Anderson,
Thanks a lot.
I got it made.(allow for a portion of their export names.)

I derived the meanings of unknown SED words from the WiKi.
It takes a good amount of time to bring understanding.
I am outside the ropes to use SED and wkhtmltopdf.

This time, I have special significance for PDF export with Tinderbox.
Ordinarily interested in LaTeX with Emacs or Spacemacs or Eclipse.
I realize that pdf export.

sed -E ‘s:href=“help[^.]*/([^.]+).html”:href="#x\1":g’ print-export-source.html > index.html

wkhtmltopdf --page-size “Letter” --dpi 765 --footer-spacing 4 --print-media-type --footer-center “[page] of [topage]” --footer-font-name “Helvetica Neue” --footer-font-size 11 --footer-line --footer-spacing 5 --header-spacing 5 --header-line --header-center “Tinderbox v7 Manual” --header-font-name “Helvetica Neue” --enable-toc-back-links toc --toc-header-text “Tinderbox v7 Manual - Table of Contents” --toc-text-size-shrink 1 --toc-level-indentation 4em “index.html” “TinderboxManual v7–2-0-bis.pdf”

Allow me to again thank you for taking advice kindly.

Thx and regards, WAKAMATSU kunimitsu

1 Like

So glad you got there in the end. :grinning:

Okay I’ve done some more digging around documentation and wkhtmltopdf issues, and it seems as though the magic flag combo is: --zoom 2.5 --disable-smart-shrinking. Set the zoom level to whatever looks good to you. No need for the --dpi flag (though maybe that just ends up doing something similar).

I’ll update the document and post in the next couple days, as I greatly prefer the wkhtmltopdf solution so far.

Thanks to @mwra for encouraging me to revisit wkhtmltopdf :slight_smile:

1 Like

Thanks. I think the dpi issue should also be resolved in the next release of `wkhtmltopdf``. The current issue is is a known regression error in the public (Mac) v0.12.4 release (and the project main devs are Win/Linux based).

FWIW, I went with wkhtmltopdf as I wanted a no-cost solution to generating the PDF with links, images and a ToC. I think I looked at pandoc at the time but it either lacked features needed or was too complex to implement.

Thanks for your helpful reply. On inspection, the earlier post was a clear spam post - link was to the same site used in other recent spam cases (whose domain I won’t advertise by repeating it). User & their posts deleted and banned.

Hi everybody.

Could someone kindly provide a how to convert Tinderbox HTML to PDF using the wkhtmltopdf-tool?

How did you @mwra and @WAKAMATSU go about it to achieve and receive a perfect PDF – with working internal Tinderbox-Links – using this very tool.

Looking forward to receiving your kindly shared insight.

Sorry, bit of a brain dump, but sort of time - and real expertise in this. wkhtmltopdf is typical of the tragedy of open source. Lots of free stuff, but just not explained for all but a very narrow audience

FWIW, here is the command line I used to make the PDf of the Tinderbox v7.5 Help file:

sed -E 's:href=\"help[^\.]*\/([^\.]+)\.html\":href=\"#x\1\":g' print-export-source.html > print-export-source-proc.html

wkhtmltopdf --outline --page-size "A4" --footer-spacing 4 --print-media-type --footer-center "[page] of [topage]" --footer-font-name "Helvetica Neue" --footer-font-size 11 --footer-line --footer-spacing 5 --header-spacing 5 --header-line --header-center "Tinderbox v7 Manual" --header-font-name "Helvetica Neue" toc --enable-toc-back-links --toc-header-text "Tinderbox v7 Manual - Table of Contents" --toc-text-size-shrink 1 --toc-level-indentation 4em "print-export-source-proc.html" "Tinderbox v7.5.2 Manual.pdf"

For your purposes the sed bit is probably immaterial and in the second bit you may need to alter file names, etc. But it might help - a bit more than wkhtmltopdf's ‘help’, anyway. :grin:

2 Likes