public function ViewsPdfBase::addPdfDocument in Views PDF 8
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
- src/
ViewsPdfBase.php, line 879 - Contains \Drupal\views_pdf\ViewsPdfTemplate.
Class
- ViewsPdfBase
- The main class to generate the PDF.
Namespace
Drupal\views_pdfCode
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;
}