TCPDF_import is not bringing in an existing file

陌路散爱 提交于 2019-12-02 01:39:52

Well, not as eloquent as I wanted, but I found something that works....

<?php
require_once "tcpdf/tcpdf.php";
require_once "FPDI/fpdi.php";
$pdf = new FPDI( 'L', 'mm', 'LETTER' ); //FPDI extends TCPDF
$pdf->AddPage();
$pages = $pdf->setSourceFile( 'test.pdf' );
$page = $pdf->ImportPage( 1 );
$pdf->useTemplate( $page, 0, 0 );
$pdf->Output( 'newTest.pdf', 'F' );
?>

Thanks to Simon who posted in http://sourceforge.net/p/tcpdf/discussion/435311/thread/66272894/

I was able to modify this - it entails running two libraries - but it works.

Create a file and call it pdfConcat.php and paste:

<?php
require_once("tcpdf/tcpdf.php");
require_once("fpdi/fpdi.php");

class concat_pdf extends FPDI {
     var $files = array();
     function setFiles($files) {
          $this->files = $files;
     }
     function concat() {
          foreach($this->files AS $file) {
               $pagecount = $this->setSourceFile($file);
               for ($i = 1; $i <= $pagecount; $i++) {
                    $tplidx = $this->ImportPage($i);
                    $s = $this->getTemplatesize($tplidx);
                    $this->AddPage('P', array($s['w'], $s['h']));
                    $this->useTemplate($tplidx);
               }
          }
     }
}
?>

Usage:

include_once("pdfConcat.php");
$pdf =& new concat_pdf();

$pdf->setFiles(array("doc.pdf","pauta.pdf", "4bp.pdf", "5bp.pdf"));
$pdf->concat();
$pdf->Output("newpdf.pdf", "I");

http://garridodiaz.com/concatenate-pdf-in-php/

Olè!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!