public function PdfTemplate::addPdfDocument in Views PDF 6
Same name and namespace in other branches
- 7.3 views_pdf_template.php \PdfTemplate::addPdfDocument()
- 7 views_pdf_template.php \PdfTemplate::addPdfDocument()
- 7.2 views_pdf_template.php \PdfTemplate::addPdfDocument()
This method adds a existing PDF document to the current document. If the file does not exists this method will return 0. In all other cases it will returns the number of the added pages.
Parameters
$path string Path to the file:
Return value
integer Number of added pages
File
- ./
views_pdf_template.php, line 648 - PDF Class to generate PDFs with native PHP. This class based on FPDF and FPDI.
Class
- PdfTemplate
- The main class to generate the PDF.
Code
public function addPdfDocument($path) {
if (empty($path) || !file_exists($path)) {
return 0;
}
$numberOfPages = $this
->setSourceFile($path);
for ($i = 1; $i <= $numberOfPages; $i++) {
$dim = $this
->getTemplateSize($i);
$format[0] = $dim['w'];
$format[1] = $dim['h'];
if ($dim['w'] > $dim['h']) {
$orientation = 'L';
}
else {
$orientation = 'P';
}
$this
->setPageFormat($format, $orientation);
parent::addPage();
// Ensure that all new content is printed to a new page
$this->y = 0;
$page = $this
->importPage($i);
$this
->useTemplate($page, 0, 0);
$this->addNewPageBeforeNextContent = true;
}
return $numberOfPages;
}