Pdf file size is huge with fpPdf. lazarus / 21-General ---------------------------------------------------------------------- meeeeeeeeee · 2025-05-12 00:56 FpPdf, text, jpeg pdf file size is huge. I'm using FpPdf with Lazarus. I use several fonts, and some small jpeg on pdf file. Pdf file size is large. I want to compress the file size, and I tried to use TPDFOption like poCompressFonts or poCompressImages, but the size wasn't get smaller. Using poNoEmbeddedFonts make the file size smaller, but occured fonts error when load fonts. Could someone give me an advice how to compress PDF file size with FpPdf using TPDFOption? ---------------------------------------------------------------------- paule32 · 2025-05-12 06:37 Creation of PDF can simply made by Text-Editor. See the RAW-Data of the PDF Files like: https://raw.githubusercontent.com/paule32/PDF_native_TextFile/refs/hea ds/main/test2.pdf Happy coding ... ---------------------------------------------------------------------- rvk · 2025-05-12 07:27 Quote from: meeeeeeeeee on May 12, 2025, 02:56:25 amUsing poNoEmbeddedFonts make the file size smaller, but occured fonts error when load fonts. Was this on the same machine the pdf was created? Not embedding fonts shouldn't be a problem if viewing on the same machine. Only if you transfer the pdf to another machine without those font, the pdf could look different (because the fonts aren't present). But in no way there should be an error on the same machine (or if the font is present on another machine). What did the error look like? Can you see if the image is duplicated with a meta-image version? Look at the uncompressed pdf and see (in a text editor) what parts are actually huge. ---------------------------------------------------------------------- Thaddy · 2025-05-12 07:55 Apart from the fonts, jpg/jpeg is already a compressed format so there is no benefit trying to compress it any further. If you need to include/embed the fonts, first consider its filesize and when it is big, find an alternative that is smaller and similar. ---------------------------------------------------------------------- rvk · 2025-05-12 08:04 Quote from: Thaddy on May 12, 2025, 09:55:58 amApart from the fonts, jpg/jpeg is already a compressed format so there is no benefit trying to compress it any further. No, but depending on how you are putting the jpeg in pdf (for example via GDI) you can end up with a compressed version (jpeg) as well as (or instead) a much larger WMF version (for example if you use Draw to put the jpg in the pdf). So maybe we need to see some code as how this pdf is formed and if it can be improved upon. And for embedding fonts... you might only want to include a subset (only the characters you use) from the font. Unicode fonts can be very large while you only use a very small part of them. I'm not sure if fpPdf supports embedding subset of fonts. ---------------------------------------------------------------------- rvk · 2025-05-12 08:11 Quote from: rvk on May 12, 2025, 10:04:28 amAnd for embedding fonts... you might only want to include a subset (only the characters you use) from the font. Unicode fonts can be very large while you only use a very small part of them. I'm not sure if fpPdf supports embedding subset of fonts. You might want to check out if adding poSubsetFont works for your fonts. ---------------------------------------------------------------------- meeeeeeeeee · 2025-05-13 00:11 Thank you for replying my question. I use these options[poCompressText, poCompressFonts, poCompressImages, poSubsetFont] and found out the specific font is the problem. Using Noto JP fonts like "Noto Sans JP Bold, Noto Serif JP Bold" pop up a error message like "Unable to extract the embedded font [GRAEAJ+Noto Sans JP Bold]. Some characters may not be displayed correctly or may not be printable.". When I don't use Noto font series, but just use font like "BIZ UDGothic", 'IPAGothic' or 'IPAexGothic', then didn't pop up any error message, and also pdf file size is compressed. So so far I thought Noto font series can't go well with TPdfOption-poSubsetFont... ---------------------------------------------------------------------- rvk · 2025-05-13 07:14 Noto Sans seems notorious for breaking pdf when embedded. I found several topics over the internet where that font seems to cause problems. One example: https://github.com/notofonts/noto-fonts/issues/1678 If you are using the OTF version of the font, you might want to switch to a TTF version to see if that helps. ---------------------------------------------------------------------- meeeeeeeeee · 2025-05-13 07:44 Dear rvk; Thank you for the information. https://moji.or.jp/ipafont/ipaex00401/ I will use IPAex font instead of Noto serif JP font. ---------------------------------------------------------------------- Thaddy · 2025-05-13 09:22 Also note poCompressFonts and certainly poCompressImages would not much towards file size: The images are already compressed and the fonts are usually vector fonts. ---------------------------------------------------------------------- PascalDragon · 2025-05-13 19:00 Quote from: paule32 on May 12, 2025, 08:37:38 amCreation of PDF can simply made by Text-Editor. While it's technically possible it's not really feasible except for the smallest of PDFs, because there are references that depend on the character count that one needs to keep track of. Any insertion or deletion would require an update of the object table of all later objects. Not to mention that streams can be compressed, you can't easily do that with a text editor. ---------------------------------------------------------------------- meeeeeeeeee · 2025-05-16 08:35 I found GhostScript to reduce PDF file. The file size got smaller, but text font color Black got a bit pale, but it works...