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?
Advertisement
Answer
The Helvetica font is added by TCPDF for two reasons:
- 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';
- 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; } }