|
Posted by Justin Koivisto on 02/06/06 16:56
Justin Koivisto wrote:
> Paul Czubilinski wrote:
>>
>> I would like to join few pdf files uploaded separetly into my website
>> into one downloable pdf file. Is it possible in php or is it neccessary
>> to download all these files one by one?
>
> I have a bookmark or at least example code on my computer in the office.
> I will see if I can dig it up tomorrow when I am there. I can't remember
> exactly how I went about doing it, but I think it was using an existing
> package I found on the net...
fpdi:
http://fpdi.setasign.de/
<?php
// This was created for use with FPDI 1.01
$dir = 'pdfs/';
$pdfs = $_POST['pdfs'];
if($pdfs) {
// this is a test file for appending pages of PDF files together to
create a new file
// define('FPDF_FONTPATH','font/');
require 'fpdi.php';
class concat_pdf extends fpdi {
var $files = array();
function concat_pdf($orientation='P',$unit='mm',$format='A4') {
parent::fpdi($orientation,$unit,$format);
}
function set_files($files) {
$this->files = $files;
}
function concat() {
foreach($this->files AS $file) {
$pagecount = $this->setSourceFile($file);
for ($i = 1; $i <= $pagecount; $i++) {
$tplidx = $this->ImportPage($i);
$this->AddPage();
$this->useTemplate($tplidx);
}
}
}
}
$pdf= new concat_pdf();
$pdf->set_files($pdfs);
$pdf->concat();
$pdf->Output("newpdf.pdf","I");
} else {
echo '<form method="post" action="index.php">';
echo '<div style="padding: 3px; font-weight: bold;">Please check the
PDFs you would like to combine into one:</div>';
$dh = opendir($dir);
while (false !== ($file = readdir($dh))) {
if (preg_match('/\.pdf$/i', $file)) {
echo '<div style="padding: 3px;"><input type="checkbox" name="pdfs[]"
value="'.$dir.$file.'" /> '.$file.'</div>';
}
}
echo '<div style="padding: 3px;"><input type="submit" name="submit"
value="Submit" /></div>';
echo '</form>';
}
?>
I did notice that there is a newer version out now, but I haven't done
anything with this for about a year now...
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Navigation:
[Reply to this message]
|