You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using large images that are scaled down, the pdf size will not decrease by downscaling. There should be an option to limit the resolution of pixel images in the resulting PDF.
This could be an option to image which could be set globally or locally like set image(max-res: 300)
or some kind of pdf export setting for the cli.
When talking about that topic, we could also think of other related options like image compression settings in pdf.
Use Case
It might be useful for everyone who uses high-res images in their typst document, especially when they face pdf file size restrictions (maybe for submission).
Reacted by Bastien Voirin, Stowy, µKöff, bjoluc, Karthik A, hpcfzl, Laurenz Stampfl, Canis Li, Dominik Schwaiger, Ownez and 8 more
@Ownezx That workaround doesn't seem to support the document metadata though, which means that text is copied with hard wrapping, and screen readers lose the reading order.
Typst emits a tagged PDF — on 0.15.1 my document has a /StructTreeRoot and 132 /S/P elements. After gs -sDEVICE=pdfwrite (Ghostscript 10.06.0) there is no /StructTreeRoot and no /Marked entry at all. -dPreserveMarkedContent=true makes no difference, with or without -dPDFUACompatibilityPolicy=1. It isn't a missing flag: pdfwrite re-interprets each page into fresh content streams, and the structure tree refers into the old ones by MCID, so by the time it writes there is nothing left to point at.
Two other things worth knowing if you do use it:
Every -dPDFSETTINGS preset downsamples with /ColorImageDownsampleType /Average, a box filter. Asking for /Bicubic explicitly looks better and comes out smaller — on a 76 MB document (ten camera-resolution photos and twelve rendered PNG maps), /printer gives 6.1 MB and this gives 3.6 MB:
It re-encodes lossless images as JPEG. For photographs that's the point; for screenshots, diagrams or rendered maps it isn't. -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode keeps them lossless, but applies to every image, so you can't have JPEG photos and lossless line art in one pass — in my case that's the difference between 3.6 MB and 24 MB.
Activity
lumpiluk commentedon Nov 2, 2023
I read this in #404 a couple of days ago:
Beiri22 commentedon Jul 9, 2024
Nice to read that, but is there any progress on this topic, since?
Ownezx commentedon Jan 6, 2026
For now there is a workaround using ghost script
c-harding commentedon Sep 18, 2026
@Ownezx That workaround doesn't seem to support the document metadata though, which means that text is copied with hard wrapping, and screen readers lose the reading order.
Typst emits a tagged PDF — on 0.15.1 my document has a
/StructTreeRootand 132/S/Pelements. Aftergs -sDEVICE=pdfwrite(Ghostscript 10.06.0) there is no/StructTreeRootand no/Markedentry at all.-dPreserveMarkedContent=truemakes no difference, with or without-dPDFUACompatibilityPolicy=1. It isn't a missing flag:pdfwritere-interprets each page into fresh content streams, and the structure tree refers into the old ones by MCID, so by the time it writes there is nothing left to point at.Two other things worth knowing if you do use it:
Every
-dPDFSETTINGSpreset downsamples with/ColorImageDownsampleType /Average, a box filter. Asking for/Bicubicexplicitly looks better and comes out smaller — on a 76 MB document (ten camera-resolution photos and twelve rendered PNG maps),/printergives 6.1 MB and this gives 3.6 MB:It re-encodes lossless images as JPEG. For photographs that's the point; for screenshots, diagrams or rendered maps it isn't.
-dAutoFilterColorImages=false -dColorImageFilter=/FlateEncodekeeps them lossless, but applies to every image, so you can't have JPEG photos and lossless line art in one pass — in my case that's the difference between 3.6 MB and 24 MB.wojpawlik commentedon Nov 6, 2026
-gis required to reduce file size.--color-image-recompress-methodis required to subsample.samekeeps lossless images lossless.--color-image-subsample-method=bicubicindeed reduces file size.Requires specifying
--color-image-subsample-dpi.grayandbitonalimages.--structuredoes nothing. It's always kept as of 1.28.6.Docs: https://mupdf.readthedocs.io/en/latest/tools/mutool-clean.html