TCPDF_import is not bringing in an existing file

后端 未结 3 1323
情深已故
情深已故 2021-01-22 17:17

I have a PDF of a blank certificate, I want to fill in two lines when the user completes a course of study, and display the PDF so they can print or download it.

I am us

相关标签:
3条回答
  • 2021-01-22 17:46

    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.

    0 讨论(0)
  • 2021-01-22 17:54

    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è!!!

    0 讨论(0)
  • 2021-01-22 17:57

    As stated in TCPDF_IMPORT documentation page at this time (2020-04-16)

    TCPDF_IMPORT !!! THIS CLASS IS UNDER DEVELOPMENT !!!

    Futhermore the free version of FPDI supports PDF up to version 1.4

    If someone else is looking for something that works easily with TCPDF, I used TCPDI from https://github.com/pauln/tcpdi. You can find some fork ready for composer too.

    The usage is quite simple and similar to FPDI. Here a snipped from my code. I have a privacy policy (a static PDF file) and want to save a copy with user name and agreement date in the footer of each page.

    // Create new PDF document
    $pdf = new TCPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    ...
    // Add the pages from the source file.
    $pagecount = $pdf->setSourceFile($localPrivacy);
    for ($i = 1; $i <= $pagecount; $i++) {
        $tplidx = $pdf->importPage($i);
        $pdf->AddPage();
        $pdf->useTemplate($tplidx);
        // Add agreement text in document footer
        $pdf->SetXY(15,282);
        $pdf->Cell(180, 5, "Documento approvato da {$fullName} il {$date}", 0, 0, 'C');
    }
    // Send PDF on output
    $pdf->Output(FOLDER_PATH . DIRECTORY_SEPARATOR . "{$userId}.pdf", 'F');
    
    0 讨论(0)
提交回复
热议问题