Why my pdf is to big? Typst export WebP images to PNG

Hi community. I have a PDF with 180 MB ( :astonished:) and my pdf reader opens the document very slow. My document has 19 images, all webp. But when compile typst converts all images to PNG (And the image now is more big, 310 KB to 13 MB).

What is the process for compile a light pdf file? And What recommendations can you give me for insert images in typst documents?

1 Like

Hi. How did you check that images are converted to PNG?

Usually having images in JPEG just works, they should be embedded as is. Might even take less space when embedded. Pretty sure you can convert them with magick from an imagemagick package.

3 Likes

Hi. How did you check that images are converted to PNG?

When I open my pdf and save the images the final file is a png. But I think is a specs of my pdf reader.

Well I can reduce the size of pdf file with solution in this post

My problem now is the performance. I work with this command:

typs wacth file.typ

But the pdf is slow and big

Any suggestion?

Yes. See https://superuser.com/questions/508723/how-to-identify-the-format-of-images-in-a-pdf.

Have you tried the solution I provided?

Double-check the command if you hand-write it, before creating a post.

I read the link for identify the format of images and it was really surprising.

I’ve using webp images. But typst is generating a pdf with very big size images.

From my terminal: pdfimages -list myfile.pdf

page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
  19     0 image    1536  2560  icc     3   8  image  no       699  0   829   829 23M  81%
  19     1 image    3120  4160  icc     3   8  image  no       700  0  1370  1370 29.2M  79%

→ Original image 1: 3.4 M | Typst pdf: 23M
→ Original image 2: 2.4 M | Typst pdf: 29.2M

Here we have a bug, a really big one (or I miss some export parameter).

A bug? Have you checked how large the images get it you convert them with another tool to a png file?

If I recall correctly, the PDF spec doesn’t support WebP so Typst has to re-encode images.

I think the best you can do is to downscale the images to a reasonable size for your document and maybe lossily convert them before useing them in your Typst document.

This thread isn’t productive/won’t go anywhere if you keep ignoring the questions and suggestions. Please, try converting to JPEG.

If I understand correctly, the status in Typst is that

So first getting a solution to the issue above, and then using one of those two formats would give you better control over final PDF output size.

Another option to get smaller output size is to use JPEG 2000: you cannot include such images directly in Typst, but you can include PDF files that contain such images. So you “just” need to first convert all your images to JPEG 2000 wrapped in PDF files (or use a single PDF container for all images, one per page, and use #image("my-images.pdf", page: xxx) for each image).

I really don’t get all this talk about JPEG (a terrible format nowadays and for a good time) when the post is about webp images.

If webp is not supported and is silently transformed into a different format, that is a considerable concern since jpeg has terrible quality and PNG has large file sizes. But no idea if this is the fault of typst itself or other libraries etc

It’s a PDF format issue: if it doesn’t support WebP, then converting the image data in some way is always required. (And some pdf viewers somehow support WebP, but the format itself does not really support it.)

1 Like

Oof I didn’t even consider that possibility, assuming that surely it would be standard enough to support these already old formats in pdf.

It seems however that they are in the process of supporting jpeg xl