Render PDFs
Set the page size and margins, keep some pages, add headers, footers, and bookmarks, and fill in the document's title with takumi pdf.
takumi pdf lays an HTML file out on pages and writes a PDF:
takumi pdf invoice.html -o invoice.pdfContent that does not fit on one page flows onto the next. Pagination covers how to control where pages break with CSS, which works the same here.
Set the page size and margins
--page and --margin take the values the CSS size and margin properties take:
takumi pdf report.html -o report.pdf --page "letter landscape" --margin "0.5in 0.75in"Pages default to A4 with a 1 cm margin, which grows to fit a header or footer. Both flags are defaults, so a @page rule in the document wins over them, as it does over Chrome's print dialog. A value CSS does not accept stops before rendering, with exit code 2.
Keep some pages
--pages keeps only the pages you list, numbered from 1:
takumi pdf book.html -o excerpt.pdf --pages 1-3,85- keeps page 5 to the end. The kept pages still count every page of the document, so page 8 keeps showing "8" in a page-number footer.
Add a header and a footer
--header and --footer each take an HTML file, drawn in the top or bottom margin of every page. An element with the class pageNumber or totalPages shows the page number or the page count:
<div style="width: 100%; text-align: center; font-size: 10px">
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
</div>takumi pdf report.html -o report.pdf --footer footer.htmlWithout --margin, the margin on that side grows to fit the header or footer. A margin you set, with --margin or the document's @page rule, stays as you set it, and a taller band then draws over the content. Leave out --margin, or give the band's side more room, such as --margin "1cm 1cm 3cm" for a tall footer. Headers & footers shows how takumi sizes the automatic margin.
A header or footer file is a fragment of HTML, not a whole page. Its stylesheets and images load like the document's, through the same file access rules.
Add a title, authors, and bookmarks
--title sets the title a PDF viewer shows, and --author adds an author. Repeat --author for more:
takumi pdf report.html -o report.pdf --title "Quarterly report" --author "Finance team"--outline adds a bookmark for each h1 to h6 heading, so a PDF viewer shows the document's sections in its sidebar.
Set a page background
--background takes a CSS color and fills every page with it, margins included:
takumi pdf poster.html -o poster.pdf --background "#fafafa"The document's own backgrounds draw over it.
Last updated on