Pages

Tuesday, December 7, 2010

TCPDF: Getting rid of hidden credit link

I often use PDF export for my web projects: for example for printable product specifications, invoices etc.
The tool of my choice is TCPDF, a php class based on FPDF: it's free and it supports UTF-8 character encoding so you can use it for (nearly) all languages.

But last time I was trying to optimize the pdf output of a php script of mine I was wondering, why there was the font "Helvetica" in the font list shown by Adobe Reader, although I was sure I just used the font "freesans".
After a little while I found the reason: TCPDF adds a credit to itself "Powered by TCPDF (www.tcpdf.org)" on the lower left corner of the last page of each document created (I changed the colour from white to light grey to make it visible):



The www.tcpdf.org part also is a link to the TCPDF website.

Not that I envy TCPDF the fame for the excellent work, but I don't want a customer of my customer to accidently open a new browser window with a website he would never use.

To get rid of that line make a new class that extends TCPDF and override the function Close() (see how nice the author tries to hide the message and the link from us) ;-)


class NOCREDIT extends TCPDF{
   function Close() { //Overwrite to get rid of that tcpdf link
      if ($this->state == 3) {
         return;
      }
      if ($this->page == 0) {
         $this->AddPage();
      }
      $this->lastpage(); 
      // The following lines are responsible for the credit,
      // so I comment them out
      //$this->SetAutoPageBreak(false);
      //$this->x = 0;
      //$this->y = $this->h - (1 / $this->k);
      //$this->lMargin = 0;
      //$this->_out('q');
      //$this->setVisibility('screen');
      //$this->SetFont('helvetica', '', 1);
      //$this->SetTextColor(255, 255, 255);
      //$msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
      //$lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
      //$this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
      //$this->setVisibility('all');
      //$this->_out('Q');
      $this->endPage();
      $this->_enddoc();
      $this->_destroy(false);
   }
}

3 comments:

Christian Schmidt said...

In recent versions of TCPDF there is a new protected variable that controls whether the hidden link is added to the PDF file.

class MyTCPDF extends TCPDF {
function setTcpdfLink($tcpdflink) {
$this->tcpdflink = $tcpdflink;
}
}

$pdf = new MyTCPDF(...);
$pdf->setTcpdfLink(false);

Anonymous said...

Thank you sir, this helps me a lot!

agusta said...

thanks for the clue :)

Post a Comment