phppdffpdiojs

OJS - using FPDI and TCPDF libs - fatal error


I'm trying to figure out a problem with adding my own "modul" in Open Journal System. I need to edit a PDF document with FPDI a TCPDF functions - adding some informations to the PDF file.

I have my own page in OJS, where I want to upload a file, then input some information into form and after submit, there is some process, which add a informations into the PDF. But when I get my page i get this error:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Cannot open C:\xampp\htdocs\ojs245 !' in C:\xampp\htdocs\ojs245\pages\stamp\pdf_parser.php:192 Stack trace: #0 C:\xampp\htdocs\ojs245\pages\stamp\fpdi_pdf_parser.php(71): pdf_parser->__construct('C:\\xampp\\htdocs...') #1 C:\xampp\htdocs\ojs245\pages\stamp\fpdi.php(128): fpdi_pdf_parser->__construct('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\ojs245\pages\stamp\fpdi.php(108): FPDI->_getPdfParser('C:\\xampp\\htdocs...') #3 C:\xampp\htdocs\ojs245\pages\stamp\class.php(15): FPDI->setSourceFile(NULL) #4 C:\xampp\htdocs\ojs245\pages\stamp\lib\tcpdf\tcpdf.php(3543): PDF->Header() #5 C:\xampp\htdocs\ojs245\pages\stamp\lib\tcpdf\tcpdf.php(3210): TCPDF->setHeader() #6 C:\xampp\htdocs\ojs245\pages\stamp\lib\tcpdf\tcpdf.php(3122): TCPDF->startPage('schval.pdf', '', false) #7 [internal function]: TCPDF->AddPage('schval.pdf') #8 C:\xampp\htdocs\ojs245\pages\stamp\fpdf_tpl.php(367): call_user_func_array(Array, Array) #9 C:\xampp\htdocs\ojs245\pages\stamp\StampHandl in C:\xampp\htdocs\ojs245\pages\stamp\pdf_parser.php on line 192

I have this structure in ojs\pages: index.php, StampHandler.inc.php where is the main function, which should make changes in the PDF:

import('classes.handler.Handler');

    class StampHandler extends Handler {
        function stampingOperation($args, $request) {
            $templateMgr = TemplateManager::getManager($request);
            $templateMgr->display('stamp/stampingOperation.tpl');
            //echo 'Operace razitkovani';
            //$templateMgr->assign('test', $promenna);
            $templateMgr->assign('test', $request->getUserVar('test'));

require_once('lib/tcpdf/tcpdf.php'); 
require_once('fpdi.php');

// Original file with multiple pages 
require_once('class.php');

        // initiate PDF
        $pdf = new PDF();
                $pdf->fullPathToFile = "TestClanek.pdf";
        // add a page
        $pdf->AddPage("schval.pdf");
        //$pdf->AddPage();

        if($pdf->numPages>1) {
            for($i=2;$i<=$pdf->numPages;$i++) {
                $pdf->endPage();
                $pdf->_tplIdx = $pdf->importPage($i);
                $pdf->AddPage();
            }
        }

        // or Output the file as forced download
            $file_time = time();

            $pdf->Output("$file_time.pdf", "F");//, "I"); 
            echo "'<a href=$file_time.pdf>Edited file</a>'";      }
    }

Could anyone have some idea, what could be the problem?

Thanks, Zbynek

edit: class.php

class PDF extends FPDI {

var $_tplIdx;
var $fullPathToFile;

  function Header() {
      echo $this->fullPathToFile;

                if(is_null($this->_tplIdx)) {

                // THIS IS WHERE YOU GET THE NUMBER OF PAGES
                $this->numPages = $this->setSourceFile($this->fullPathToFile);
                $this->_tplIdx = $this->importPage(1);
                } 

                if($this->page > 1) {      
                    $this->SetFont('helvetica', 'I', 10); 
                    $this->SetTextColor(0);
                    $this->Write(15, $_POST["casopis"] .", Cislo: ". $_POST["rocnik"]."/0".$_POST["cislo"].", Autor: ".$_POST["autor"]."\n");  // ."\n"  border, 1);

                    // generování času a podmínka pro časové razítko
                    SetLocale(LC_ALL, "Czech");
                    $cas = StrFTime("%H:%M:%S", Time());
                    if($_POST["cas_razitko"]=="ok") {
                        // pozice   $this->SetXY(30, 30);
                        $this->Write(0, "Cas upravy: ".$cas); //."\n");          //." ", '', 0, 'L', true, 0, false, false, 0     15, 
                    }
                    // pokud je vlastní text - potom vytiskni:
                    if($_POST["text_razitko"]=="ok") {
                        //$this->SetXY(30, 30);
                        $this->Write(0, $_POST["text"]);
                    }

                    $style = array(
                      'border' => 1,
                      'padding' => 'auto',
                      'fgcolor' => array(0,0,0),
                      'bgcolor' => array(255,255,255)
                      );

                    if($_POST["qr_kod"]=="ok") {
                    $this->write2DBarcode($_POST["casopis"].", ".$_POST["autor"], 'QRCODE,L', 180, 3, 20, 20, $style, 'N');
                    }

                    $this->Image('logo.png', 100, 2, 75,7);          


                }

      $this->useTemplate($this->_tplIdx, 0, 0,200);

    }

    }

Solution

  • The var $fullPathToFile is not global in your calling class, which results in passing null to setSourceFile() in your PDF class... you should change this to a property instead:

    $pdf->fullPathToFile = "...";
    

    later in your PDF class:

    $this->setSourceFile($this->fullPathToFile);