I’m using https://github.com/matcornic/hugo-theme-learn as a documentation website. I’m looking for a way to provide an offline version of the website as PDF. This would assume to be able to convert Markdown to PDF, but especially order page in the right way before converting the data.
I don’t believe there is a way to do this automatically with Hugo. There are some default arguments being passed to helpers like Pandoc, but last time I checked I couldn’t find out to change them:
Once those can be changed then you should be able to include PDF generation arguments for Pandoc.
There are couple alternative options.
The easiest would probably be to create a wrapper script around Pandoc that adds these arguments. Unless you can get help from someone else with this, I don’t have the time to invest in doing it for you.
PDF documents can be created from a custom output format template, but this is probably way more complicated than it is worth which is why it hasn’t been done.
I’ve done it recently, and this is how I’ve done it:
There’s a page in Hugo, with a different layout, that combines all pages and outputs an HTML that is suitable for PDF. Then, this is the [simplified] build script I run each time I want to update my website:
i’m working on Paged.js, an html to pdf solution that follows the w3c standards, to print books easily. Incidently, i made our new website using Hugo, and setup a paged.js exemple. Check the website i made using Hugo (for paged.js, the lib that let you print and make PDF from HTML : https://www.pagedjs.org
you got a button top right on this page to set up the preview. Once it’s done, you only need to print from the browser, and you’re all set. Browser side printing as it should be
Create a new directory in the content directory. I’ve called it “all-content”.
Add a simple index.md file to that directory. The content is not important.
Right now, this new directory will use the default layout, which is not fine for our purpose. Create a directory with the same name in layouts; e.g., /layouts/all-content/. Now you can define a new layout for this page.
Create /layouts/all-content/list.html, with a layout that includes all pages on the website. Use my second reply to the original post above as a starting point and then refine it to match your preferences.
Create a build script to first build the website using Hugo, and then convert /public/all-content/index.html to pdf. Use my first reply above as a starting point and then adjust it to your need. You may need to install a few things such as wkhtmltopdf too.
Refine the rest of the website by excluding that page from the sitemap and RSS feed, etc.