2
votes

I'm making a PDF with TCPDF, and I'm trying to make the file as small as possible. The font I'm using is Open Sans. I'm not (intentionally, at least) using Helvetica anywhere in the PDF. When I view the included fonts with Adobe Reader in my outputted PDF file, both Open Sans and Helvetica are listed. I have noticed that if I AddFont() other fonts, the outputted PDF gets bigger.

To save space, how can I tell TCPDF to not include Helvetica in the file?

4

4 Answers

1
votes

The Helvetica font is added by TCPDF for two reasons:

  1. On initialization the TCPDF class sets the default font to Helvetica (in the constructor) and therefore adds this font to the fonts list of the document.

For older versions: To prevent this, you can edit the file config/tcpdf_config.php and change the constant PDF_FONT_NAME_MAIN to your desired default font name (should be around line 155). Note that you must not use any core font because they will never be embedded.

For newer versions: Define PDF_FONT_NAME_MAIN with your desired default font name before including the TCPDF files. Example:

define('PDF_FONT_NAME_MAIN', 'freesans');
include_once 'path/to/tcpdf.php';
  1. TCPDF adds an invisible link "Powered by www.tcpdf.org" at the bottom of the page.

To prevent this you have to use an override class like this:

class MyPdf extends TCPDF {

    public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
        // call parent constructor
        parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);
        // disable the tcpdf link
        $this->setTcpdfLink(false);
    }

    /**
     * Allows to disable the invisible "Powered by www.tcpdf.org" link at the bottom of the page.
     * @param type $tcpdflink
     */
    public function setTcpdfLink($tcpdflink = true) {
        $this->tcpdflink = $tcpdflink ? true : false;
    }

}
0
votes

The Helvetica font is one of the standard 14 core PDF fonts, so it is not embedded in the PDF when it is used. If you look in the TCPDF fonts directory you will notice that the Helvetica file only contains a description of the font and not a copy of the font. Therefore it shouldn't be significantly increasing the file size.

Solution

The Helvetica font is set as the default font in the TCPDF config files. From my testing, it appears that this causes it to be set as a font in the generated PDF files even when it is not used. Changing the default fonts in your TCPDF configuration files should prevent this from happening.

0
votes

I have to face the same issue. I have tried the JOR solution. its correct but it still shows the Helvetica font family in my pdf.

for my pdf, I am using SVG image.so it displays the Helvetica . in the tcpdf.php protected property called $svgstyles has the SVG font family as Helvetica.

0
votes

Just find $tcpdflink in tcpdf.php and make that variable false. This works for me