I need to insert pages from a PDF in my document, but I can’t find anything about that in the documentation… Is it possible?
Currently it’s not possible. See this issue on GitHub for a discussion of why.
User balping described a way to achieve this even before support is added in Typst.
edit: after re-reading your question I realized you might want to insert entire pages between the pages of your document. The linked GitHub issue is about adding PDFs as figures into a document.
To extend on @gezepi’s answer, here are some considerations for the two use cases:
Including a PDF as figure
This requires Typst to ship with a PDF reader and renderer, the issue here is mostly complexity and how to integrate a solution that works on many platforms and how to do this efficiently.
One possible workaround for this is linked directly, which, from my understanding edits the PDF in post to add the external PDFs using mupdf. That’s pretty impressive but comes with some downsides:
- it’s not integrated into Typst and will not work on the WebApp or with other tools like tinymist
- this means it’s impossible to preview on the WebApp at this moment and cumbersome on a local installation
- it requires the correct python and python packages installation
For one of cases you can also just use an external converter to turn a PDF into an SVG and include that.
#image("page.svg")
Inserting full pages from another PDF
I can’t speak for the primary maintainers, but I don’t see this as being supported within Typst anytime soon. The complexity lies within the inherent complicated structure of PDFs, merging those is no trivial task, once again Typst needs a PDF reader to correctly read in the structure of the document and extract the relevant parts for re-export.
A workaround for this is using an external tool which can stitch together PDFs. Unfortunately, these are usually paid with limited number of free uses. Another workaround is to turn your the pages of your external PDF into SVGs and using them as the background on a completely empty page. Here’s an example:
// include a certain number of pages with specific names
#let count = 3
#[
// this depends on you needs, you may omit parts of this
// we reset the styles for the pages here to ensure we don't draw
// over the included pages
#set page(numbering: none, footer: none, header: none, /* ... */)
#for p in range(0, count + 1) {
// using `page` to ensure each included page is it's own page
// in the final document
// using `page.background` to ensure we use the margins too
page(background: image("page" + str(p) + ".svg"))
}
]
// reset our page counter to ensure they don't interfere with it
// this depends on your document, you may omit this
#counter(page).update(n => n - count)
There are some caveats, like the manual work that goes into conversion of the pages, choosing the right page and image size, but it’s technically possible today. However, if you find a tool which stitches PDFs for free I’d probably go with that and simply do it in post, this probably also depends on how often such a document is edited.
The “usually” part is highly subjective, because for me, this external tool was always free and open source. It’s called pdftk
and I even made a pdfmerge
wrapper script for pdftk input.pdf... output output.pdf flatten
. Moreover, looks like pdftk is cross-platform so should be available to the majority of people.
Thank you all! All your points are relevant, but there’s also another: inserting pages as SVG backgrounds turns impossible to select text on those pages (or so I think, I didn’t test this in Typst). This makes a document much less accessible to assistive technologies.
So yeah, I understand there are many technical considerations and difficulties, but I really think the ability to insert PDF pages is a must for Typst, as it’s a tool mostly geared towards technical, durable (and in this regard, accessible) documents.
If all you want is inserting entire pages, you can merge the PDFs after the fact, like previously mentioned
I found a comment by @LaurenzV that confirms that it will be possible in the next release: Allow inserting PDFs as figures · Issue #145 · typst/typst · GitHub. But I’m not 100% sure if this is already possible if compiled from source or not yet. You can try, if you want.
A lot of people think this way, but for now we can only patiently wait for when the issue is resolved.
Thank you! That’s very good news! As I’m not currently in a rush with this (my deadline is February 2025) I’ll wait.
Thank you for sharing this, I did not find it initially when looking through the whole github issue, so I was quite bummed out, since I have a lot of hope in Typst, I am really enjoying learning it - so glad to see it is getting the tools it needs for minimum viability in professional settings, its already great for hobby use!