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"--page also takes the ISO sizes CSS does not name, A0 to A10 and B0 to B10, such as A1 or A0 landscape.
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.
Leave the cover without a header
--header and --footer draw on every page. For a header the cover leaves out, draw it with an @page margin box in the document, and clear it on the first page:
@page {
@top-center {
content: "Quarterly report";
}
}
@page :first {
@top-center {
content: none;
}
}Headers & footers covers the margin boxes and the page counters they can show.
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.
Make a poster
Give the poster one page with no margin, and size its root box with 100vh, which is the page's height in a PDF:
<style>
body {
margin: 0;
height: 100vh;
}
</style>takumi pdf poster.html -o poster.pdf --page A1 --margin 0A height in pixels that rounds past the page adds a blank page. To find content that runs past the page, give takumi paint the page size in CSS pixels, --width 2245 --height 3179 for A1, and look for the boxes it marks past the bottom edge:
takumi paint poster.html -o - --width 2245 --height 3179Put one slide on each page
Give the pages the slide's size, and break a page after each slide:
<style>
@page {
size: 1920px 1080px;
margin: 0;
}
body {
margin: 0;
}
section {
height: 1080px;
break-after: page;
}
</style>
<section>First slide</section>
<section>Second slide</section>takumi pdf deck.html -o deck.pdfEach <section> fills one 16:9 page of 1920×1080 CSS pixels. The break after the last slide adds no blank page.
Render Markdown
takumi reads HTML only. Convert Markdown with any converter, such as pandoc, and pipe its HTML into takumi pdf -:
pandoc notes.md | takumi pdf - -o notes.pdf --root . --outlineStandard input grants no directory, so --root . lets relative images in the Markdown load. --outline turns its headings into bookmarks.
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