Recent

Author Topic: Pdf file size is huge with fpPdf.  (Read 1065 times)

meeeeeeeeee

  • New Member
  • *
  • Posts: 17
Pdf file size is huge with fpPdf.
« on: May 12, 2025, 02:56:25 am »
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

  • Hero Member
  • *****
  • Posts: 516
  • One in all. But, not all in one.
Re: Pdf file size is huge with fpPdf.
« Reply #1 on: May 12, 2025, 08:37:38 am »
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/heads/main/test2.pdf

Happy coding
...
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

rvk

  • Hero Member
  • *****
  • Posts: 6777
Re: Pdf file size is huge with fpPdf.
« Reply #2 on: May 12, 2025, 09:27:35 am »
Using 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

  • Hero Member
  • *****
  • Posts: 17198
  • Ceterum censeo Trump esse delendam
Re: Pdf file size is huge with fpPdf.
« Reply #3 on: May 12, 2025, 09:55:58 am »
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.
« Last Edit: May 12, 2025, 09:57:47 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

rvk

  • Hero Member
  • *****
  • Posts: 6777
Re: Pdf file size is huge with fpPdf.
« Reply #4 on: May 12, 2025, 10:04:28 am »
Apart 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.
« Last Edit: May 12, 2025, 10:08:12 am by rvk »

rvk

  • Hero Member
  • *****
  • Posts: 6777
Re: Pdf file size is huge with fpPdf.
« Reply #5 on: May 12, 2025, 10:11:25 am »
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.
You might want to check out if adding poSubsetFont works for your fonts.

meeeeeeeeee

  • New Member
  • *
  • Posts: 17
Re: Pdf file size is huge with fpPdf.
« Reply #6 on: May 13, 2025, 02:11:34 am »
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

  • Hero Member
  • *****
  • Posts: 6777
Re: Pdf file size is huge with fpPdf.
« Reply #7 on: May 13, 2025, 09:14:10 am »
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

  • New Member
  • *
  • Posts: 17
Re: Pdf file size is huge with fpPdf.
« Reply #8 on: May 13, 2025, 09:44:22 am »
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

  • Hero Member
  • *****
  • Posts: 17198
  • Ceterum censeo Trump esse delendam
Re: Pdf file size is huge with fpPdf.
« Reply #9 on: May 13, 2025, 11:22:00 am »
Also note poCompressFonts and certainly poCompressImages would not much towards file size: The images are already compressed and the fonts are usually vector fonts.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6007
  • Compiler Developer
Re: Pdf file size is huge with fpPdf.
« Reply #10 on: May 13, 2025, 09:00:02 pm »
Creation 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

  • New Member
  • *
  • Posts: 17
Re: Pdf file size is huge with fpPdf.
« Reply #11 on: May 16, 2025, 10:35:12 am »
I found GhostScript to reduce PDF file. The file size got smaller, but text font color Black got a bit pale, but it works...

 

TinyPortal © 2005-2018