This is similar to this post .
I want to merge one external pdf into a typst-generated one, with something like
pdftk A=a1.pdf B=b1.pdf cat A1-3 B1-3 A4-end output combined.pdf
In a dynamic document, I do not know the page number where to insert the pdf, so my idea was to get the page number from some <insert_here> marker. From the previous post, I learned that writing from typst is not possible (fair enough). Is there any alternative other than using some search into the pdf to find the correct location?
ensko
February 17, 2026, 9:58am
2
I gave this advice for a similar issue on Discord recently:
Basically, you’d insert a page number as metadata into your document (edited to reflect feedback):
#context [#metadata(here().page())<insert_here>]
Then, query that with
typst query --one --field value '<insert_here>'
and insert the value you got into your pdftk command
2 Likes
I had tried with pdftk, pdfinfo and awk, but your’s is much simpler.
1 Like
… but I failed to get it to work.
=== Case report form (CRF)
#context metadata(here().page()) <crfhere>
=== Participant informed consent
#metadata("This is a note") <note>
Test
typst query index.typ "<crfhere>" --field value
[]
typst query index.typ "<note>" --field value
["This is a note"]
ensko
February 17, 2026, 1:42pm
5
whoops, I think you need brackets (edited to reflect Andrew’s feedback):
#context [#metadata(here().page())<crfhere>]
because otherwise, the label is attached to the context instead of the metadata…
I’ll edit my original answer to reflect that
2 Likes
Andrew
February 20, 2026, 10:38am
6
1 Like