Smith Smithy
Smith Smithy

Reputation: 585

How to convert a series of images into one pdf document in php

I have searched for a while and can not find a clear answer to this.

I have a folder with images: 001.png, 002.png ....etc.

what I have tried.

$allImages = 'folder/001.png folder/002.png folder/003.png';
//and
$allImages = 'folder/001.png,folder/002.png,folder/003.png';
//and
$allImages = '-adjoin folder/001.png -adjoin folder/002.png -adjoin folder/003.png';

then:

exec(convert $allImages folder/newdoc.pdf);
//and
exec(convert -density 150 -format pdf{} ".$all_images folder/newdoc.pdf);

This only puts one page into the pdf and the pdf has a header of png so it really is not readable by a pdf viewer.

I do not want to use (convert *.png newdoc.pdf) as i need the pdf in a certain sequence. EDIT: this does not work either.

Upvotes: 3

Views: 6082

Answers (4)

John Alexander Betts
John Alexander Betts

Reputation: 5206

You can use mPDF. All the information you need is here: mPDF Github project

Upvotes: 3

Sunil Verma
Sunil Verma

Reputation: 2500

You need to look into this old question

How can I convert a series of images to a PDF from the command line on linux?

you can use imagemagick for this.

Upvotes: 0

Lenny Bruyninckx
Lenny Bruyninckx

Reputation: 95

FPDF is all need, see this tutorial page: http://www.fpdf.org/en/tutorial/tuto2.htm And here you can find the manual: http://www.fpdf.org/en/doc/index.php

Do something similar like this example:

<?php
require_once('fpdf.php');
$pdf = new FPDF('P', 'mm', 'A4');
$pdf->AddPage();
foreach($pictures as $picture) {
    $pdf->Image($image,'0','0');
    $pdf->Ln();
}
$pdf->Output();
?>

Upvotes: 1

Quicker
Quicker

Reputation: 1246

From looking at imagemagick.org I would conclude it to work like this:

$allImages = '-adjoin folder/001.png -adjoin folder/002.png -adjoin folder/003.png';
exec("convert $allImages folder/newdoc.pdf");

Upvotes: 1

Related Questions