Hello everyone,
I have my own script for editing the PDF - out of OJS, I load file, and after I call a script, it succesfuly edit my PDF.
I’m working on plugin for OJS, and I’m trying to figure out a problem, that when I place the script into the OJS journal, I get this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Cannot open TestClanek.pdf !' 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('TestClanek.pdf') #1 C:\xampp\htdocs\ojs245\pages\stamp\fpdi.php(128): fpdi_pdf_parser->__construct('TestClanek.pdf') #2 C:\xampp\htdocs\ojs245\pages\stamp\fpdi.php(108): FPDI->_getPdfParser('TestClanek.pdf') #3 C:\xampp\htdocs\ojs245\pages\stamp\class.php(12): FPDI->setSourceFile('TestClanek.pdf') #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('', '', false) #7 [internal function]: TCPDF->AddPage() #8 C:\xampp\htdocs\ojs245\pages\stamp\fpdf_tpl.php(367): call_user_func_array(Array, Array) #9 C:\xampp\htdocs\ojs245\pages\stamp\lib\tcpdf\tcpdf.php(2962): FPDF_TPL->AddPage() in C:\xampp\htdocs\ojs245\pages\stamp\pdf_parser.php on line 192
I Understand, that there is problem with loading a file (pass the NULL), but i’m not able to find out, where is the problem). Could anyone help me? Here is my code of app:
import('classes.handler.Handler');
class StampHandler extends Handler {
function stampingOperation($args, $request) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->display('stamp/stampingOperation.tpl');
require_once('lib/tcpdf/tcpdf.php'); //$_SERVER['DOCUMENT_ROOT'].
require_once('fpdi.php'); //$_SERVER['DOCUMENT_ROOT'].
require_once('class.php');
// initiate PDF
$pdf = new PDF();
$pdf->fullPathToFile = "TestClanek.pdf";
if($pdf->numPages>1) {
for($i=2;$i<=$pdf->numPages;$i++) {
$pdf->endPage();
$pdf->_tplIdx = $pdf->importPage($i);
$pdf->AddPage();
}
}
$file_time = time();
$pdf->Output("$file_time.pdf", "F");//, "I");
echo "Link - edited PDF: '<a href=$file_time.pdf>Edited file</a>'"; }
}
and class.php
class PDF extends FPDI {
var $_tplIdx;
var $fullPathToFile;
function Header() {
if(is_null($this->_tplIdx)) {
$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, "Cislo: 1, autor 2 cislo 3\n");
$this->Image('logo.png', 100, 2, 75,7);
} //end IF
$this->useTemplate($this->_tplIdx, 0, 0,200);
} //end HEADER
} //end CLASS
It works as expected, when i ran the script out of OJS. Thanks a lot for help!
duff