Reputation: 1
Not able to locate requested PDF
Here is my function:-
function genpdf()
{
$this->load->library('session');
$this->load->library('PDFMerger');
$a=$_POST['a'];
$b=$_POST['b'];
$pdf = new PDFMerger;
$pdf->addPDF("samplepdfs/$a")
->addPDF("samplepdfs/$b")
->merge('file', 'http://localhost/student/samplepdfs/genpdf.pdf');
}
I need to merge different PDF into one. I am using fpdf & fpdi. I want it to be done with codeigniter. Another solutions(different methods than mentioned above) are also welcome.
Upvotes: 0
Views: 3108
Reputation: 100175
Its better to check if pdf file exists before trying to add it, as you are fetching the pdf filename from POST
data, like:
...
$a=$_POST['a'];
$b=$_POST['b'];
$error = false;
$errorMsg = "";
$pdf = new PDFMerger;
if( file_exists("samplepdfs/$a") ) {
$pdf->addPDF("samplepdfs/$a");
}
else {
$error = true;
$errorMsg .="File:".$a." not found <br />";
}
if( file_exists("samplepdfs/$b") ) {
$pdf->addPDF("samplepdfs/$b")
}
else {
$error = true;
$errorMsg .="File:".$b." not found";
}
//merge pdf if no error
if( !$error ) {
$pdf->merge('file', 'http://localhost/student/samplepdfs/genpdf.pdf');
}
else {
echo $errorMsg;
}
Upvotes: 2