Reputation: 6810
I want to create a pdf with multiple images in it. The images are highcharts that I send in array with jquery download from javascript to my php action.
In my action I get an array with multiple base64 encoded strings. Like this.
To create my pdf I have this code:
// INCLUDE TCPDF LIBRARY
require_once 'tcpdf/tcpdf.php';
try {
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('SurveyAnyplace');
$pdf->SetTitle('Question Results');
$pdf->SetSubject('SurveyAnyplace Quiz');
$pdf->SetKeywords('question, PDF, results, surveyanyplace, quiz');
$pdf->setPrintHeader(false); // no header
$pdf->setPrintFooter(false); // no footer
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->AddPage();
$pdf->setJPEGQuality(75);
$pdf->Image('/images/logo.png', 25, 10, 154, 25, 'PNG', 'http://www.surveyanyplace.com', '', true, 150, '', false, false, 1, false, false, false);
for($i = 0; $i < count($imagesarray); $i++){
$pdf->Image($imagesarray[$i], 25, 60, 154, 100, 'PNG', 'http://www.surveyanyplace.com', '', true, 150, '', false, false, 1, false, false, false);
}
$horizontal_alignments = array('L', 'C', 'R');
$vertical_alignments = array('T', 'M', 'B');
//Change To Avoid the PDF Error
ob_end_clean();
// If you first want preview in browser -> CHOOSE I (params: http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1)
$pdf->Output($quizname . '-report.pdf', 'D');
}
catch (Exception $e) {
die ('Application error: ' . $e->getMessage());
}
As you can see I loop through the images array to output the images.
But when I open the document, only the last image is shown.
What's the problem here?
Upvotes: 0
Views: 1211
Reputation: 4309
The problem is that you are placing all of your images at the same position on the page, so each image is being placed on top of the previous image, which is why you're only seeing the last one.
Upvotes: 1