TCPDF и FPDI с несколькими страницами
Это выглядит как самая простая вещь, но я не могу заставить ее работать.
Мне нужно добавить текст на первую страницу многостраничного PDF (может быть любое количество страниц)
Используя этот код на двухстраничном pdf (без цикла for, просто используя $ pdf-> importPage (2)), я получаю две страницы, но вторая страница является повторением первой страницы. Текст написан только на первой странице, и это хорошо, но мне нужно, чтобы все страницы были включены в выходной pdf. Вот мой код
// Original file with multiple pages
$fullPathToFile = 'full/path/to/file.pdf';
class PDF extends FPDI {
var $_tplIdx;
function Header() {
global $fullPathToFile;
if (is_null($this->_tplIdx)) {
$this->setSourceFile($fullPathToFile);
$this->_tplIdx = $this->importPage(1);
}
$this->useTemplate($this->_tplIdx);
}
function Footer() {}
}
// initiate PDF
$pdf = new PDF();
$pdf->setFontSubsetting(true);
// add a page
$pdf->AddPage();
// The new content
$pdf->SetFont("helvetica", "B", 14);
$pdf->Text(10,10,'Some text here');
// How to get the number of pages of original pdf???
// $numPages = $pdf->getNumPages(???);
// Carry on adding all remaining pages starting from page 2
for($i=2;$i<=$numPages;$i++) {
// Add another page
$pdf->AddPage();
// Do I need to declare the source file here?
// $pdf->setSourceFile($fullPathToWD);
$pdf->importPage($i);
}
// Output the file as forced download
$pdf->Output('theNewFile.pdf', 'D');
Ссылки на документы
Классы TCPDFhttp://www.tcpdf.org/doc/code/classTCPDF.html#a5171e20b366b74523709d84c349c1ced
FPDI классыhttp://www.setasign.de/support/manuals/fpdi/
FPDF_TPL Классыhttp://www.setasign.de/support/manuals/fpdf-tpl/