Menu

TCPDF_IMPORT

Help
2014-08-28
2014-09-03
  • Philip Hendrix

    Philip Hendrix - 2014-08-28

    Hello all, I'm very new to TCPDF and so far it looks great for what we need. The only thing we sure need is the tcpdf_import class which is still experimental. When I try to use it, it gives no error but the page on which the imported PDF should come, stays blank. Any Help ?
    See my code:
    <?php header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); ?>
    <?php

    $INCL_DIR = $_SERVER["DOCUMENT_ROOT"]."/php_incl/";
    $INCL_FPDF = $_SERVER["DOCUMENT_ROOT"]."/../Global/fpdf/";
    $INCL_FPDI = $_SERVER["DOCUMENT_ROOT"]."/../Global/fpdi/";

    //get user logon on to website
    //print_r($_SERVER); //get all the server variables
    $vzet = strtoupper(substr($_SERVER["LOGON_USER"],0,3)); //get domain\username
    $user = strtoupper($_SERVER["LOGON_USER"]); //get domain\username

    //////////////////////////////////////////////////////////
    //vanaf hier print to pdf
    //////////////////////////////////////////////////////////

    // Include the main TCPDF library (search for installation path).
    require_once('tcpdf_include.php');
    require_once('../../../../../tcpdf/tcpdf_import.php');

    // create new PDF document
    $pdf = new TCPDF_IMPORT(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    //$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Author');
    $pdf->SetTitle('Title');
    $pdf->SetSubject('Subject');
    $pdf->SetKeywords('Key1, Key2, Key3');

    // set default header data
    //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
    //$pdf->SetHeaderData('','','','');
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);

    // set header and footer fonts
    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

    // set default monospaced font
    // $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

    // set some language-dependent strings (optional)
    if (@file_exists(dirname(FILE).'/lang/eng.php')) {
    require_once(dirname(FILE).'/lang/eng.php');
    $pdf->setLanguageArray($l);
    }

    // ---------------------------------------------------------

    // set font
    $pdf->SetFont('dejavusans', '', 8);

    // add a page
    $pdf->AddPage();

    $html = 'Some text on first page';

    // output the HTML content
    $pdf->writeHTML($html, true, false, true, false, '');

    if ( file_exists('test.pdf') )
    {
    $pdf->AddPage();
    $pdf->importPDF('test.pdf');
    }
    else
    {
    // echo 'File doesn´t exists';
    }

    // reset pointer to the last page
    $pdf->lastPage();

    // ---------------------------------------------------------

    //Close and output PDF document
    $pdf->Output('test.pdf', 'I');

    //============================================================+
    // END OF FILE
    //============================================================+

    ?>

     
  • Simon

    Simon - 2014-08-28

    Have you looked at the source of importPDF() ?

    I don't think it does anything yet. It is still under development.

    I import PDFs using FPDI.

     
  • Philip Hendrix

    Philip Hendrix - 2014-08-29

    I did look at the source and the file is being read, only the fallback to the pdf isn't working properly I think, return $data isn't working either.

    Can you give an example how to combine tcpdf and FPDI ? I need to import other PDF doc's while generating the source with TCPDF.
    Thx

     
  • Simon

    Simon - 2014-08-29

    Something like this:

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

    Philip Hendrix - 2014-08-29

    Thx !!! Great !!! will test immediately.

     
  • Philip Hendrix

    Philip Hendrix - 2014-09-03

    My Solution to import all pages:
    if ( file_exists($strFolder.'\test.pdf') )
    {
    $pdf->lastPage();
    $sw_bookmark = 0;
    $pages = $pdf->setSourceFile($strFolder.'\test.pdf');
    for ($i = 1; $i <= $pages; $i++)
    {
    $pdf->AddPage();
    if ( $sw_bookmark == 0 )
    {
    $pdf->Bookmark('to add bookmark if', 1, 0, '', 'B', array(0,64,128));
    $sw_bookmark = 1;
    }
    $page = $pdf->importPage($i);
    $pdf->useTemplate($page, 0, 0);
    }
    }
    else
    {
    echo 'File doesn´t exists';
    }

     
    • elite-fusion

      elite-fusion - 2014-09-03

      Hello Philip,

      I just sent you a Private Message in hopes that you might be able to assist me with this as I am also, very new to this as well as PHP in general.
      Please reply when you get a chance :) Your help will be greatly appreciated :)

       

Log in to post a comment.