Skip to content
Advertisement

PHP + tcpdf: How can I reduce file size when generate with local language

Now my web app using class tcpdf to convert all pdf file (in English) and file size is around 500K.

But when I change the font style to my local language (Free-serif) then file size is over 1M (Pictures, tables does not change).

If I switch back to normal font, file size is small but non-English text become unreadable.

Advertisement

Answer

You really should read the TCPDF fonts documentation. What happens is that the font you specified is embedded within the PDF. This will make sure that people that don’t have that font on their computer will still be able to see the document as you intended (ie. with the correct font).

You can change the default behaviour using the $subset parameter of AddFont/SetFont.

The relevant info from the TCPDF source :

@param $subset (mixed) if true embed only a subset of the font (stores 
only the information related to the used characters); if false embedd full 
font; if 'default' uses the default value set using setFontSubsetting(). 
This option is valid only for TrueTypeUnicode fonts. If you want to enable 
users to change the document, set this parameter to false. If you subset 
the font, the person who receives your PDF would need to have your same 
font in order to make changes to your PDF. The file size of the PDF would 
also be smaller because you are embedding only part of a font.

So if you don’t want your PDF to become larger : stick to the standard (core) PDF fonts as specified in the docs.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement