Quick Start to Git Submodule

The Problem

As a developer, having loads of reusable code makes work much easier and enjoyable. I’ve got into the habit of breaking the applications I develop in CakePHP into plugins so I can reuse the plugins in other projects. It wasn’t long before I hit some issues. For example, I used plugin X in project A. Then copied plugin X to project B and added new functionality. Not so long after that I extended plugin X in project A. So now I have two “branches” of plugin X and merging them is another task altogether. That project A and project B are git repos doesn’t help either since I don’t want to merge project A and project B.

Continue reading


How to create personalized PDF Templates using TCPDF and FPDI

I recently had to output a personalized copy of a document to a few hundreds of users. Unfortunately, TCPDF cannot open/read an existing PDF nor can it use a PDF as template.

Fortunately, I stumbled on FPDI which extends TCPDF with this feature. You can load an existing PDF page and use it as a template. It’s pretty easy to implement so I won’t go into the details. Just checkout the demo.



Example (From FPDI Site – Link Above)

// just require TCPDF instead of FPDF

class PDF extends FPDI {
 * "Remembers" the template id of the imported page
 var $_tplIdx;

 * include a background template for every page
 function Header() {
 if (is_null($this->_tplIdx)) {
 $this->_tplIdx = $this->importPage(1);

 $this->SetFont('freesans', 'B', 9);
 $this->SetXY(60.5, 24.8);
 $this->Cell(0, 8.6, "TCPDF and FPDI");

 function Footer() {}

// initiate PDF
$pdf = new PDF();
$pdf->SetAutoPageBreak(true, 40);

// add a page

// get esternal file content
$utf8text = file_get_contents("cache/utf8test.txt", true);

$pdf->SetFont("freeserif", "", 12);
// now write some text above the imported page
$pdf->Write(5, $utf8text);

$pdf->Output('newpdf.pdf', 'D');