473,382 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

joining pdf files in php

Hello,

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?

Thx for help,
Paul

Feb 5 '06 #1
5 5855
"Paul Czubilinski" <pa***@deso.pl> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I would like to join few pdf files uploaded separetly into my website
into one downloable pdf file.


I use the free PDF library called FPDF with the FPDI extension at
fpdi.setasign.de

This lets you create a PDF file and then import other PDF files into it.

The documentation for FPDF mentions two free tools to catenate PDF files,
but I have no experience with them (see item #20 in the FAQ for FPDF).
Feb 5 '06 #2
Paul Czubilinski wrote:
I would like to join few pdf files uploaded separetly into my website
into one downloable pdf file.


If you've got Ghostscript installed on your server, it's easy enough to
join a few PDFs together...

<?php
# Where is Ghostscript installed?
$gs = '/usr/bin/gs';

# Which files do we want to join together?
# Specify them in the right order!
$infiles = array(
'/home/me/public_html/pdf/coverpage.pdf',
'/home/me/public_html/pdf/part1.pdf',
'/home/me/public_html/pdf/part2.pdf',
'/home/me/public_html/pdf/part3.pdf',
'/home/me/public_html/pdf/index.pdf'
);

# What is the output file name?
$outfile = '/home/me/public_html/pdf/out.pdf';

# Assemble arguments to supply to Ghostscript.
$args = "-dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite ";
$args .= "-sOutputFile='{$outfile}' ";
foreach ($infiles as $f)
$args .= "'{$f}' ";

# Call Ghostscript to do the real work.
system("$gs $args");
?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Feb 5 '06 #3
Paul Czubilinski wrote:
Hello,

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?

Thx for help,
Paul


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...
Feb 6 '06 #4
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.'" /> &nbsp;'.$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 - ju****@koivi.com
http://koivi.com
Feb 6 '06 #5
Many thanks Justin, I will try your code.

Paul

Feb 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
Hi all, I have 2 files containing Id numbers and surnames (these files essentially contain the same data) I want to select distinct() and join on id number to return a recordset containing every...
3
by: JHenstay | last post by:
I've been doing quite alot of reading on C++ and classes, however, everything I read just talks about the code itself and not the location of the code. My question is, what if you want to...
9
by: Eric Sabine | last post by:
Can someone give me a practical example of why I would join threads? I am assuming that you would typically join a background thread with the UI thread and not a background to a background, but...
5
by: Hugh Janus | last post by:
Hi group, I have an app that streams files over the network. What I want to be able to do now is select a folder and stream the entire contents of that folder over the network. I could simply...
1
by: sarffi | last post by:
Hi. i m getting a problem regarding joining of xml files of size greater than 1GB in java.the error i mgetting is "out of heap memory space" in java....So,plz suggest me the possible solutions....
7
by: mosscliffe | last post by:
I have 4 text files each approx 50mb. I need to join these into one large text file. I only need to do this very occasionally, as the problem has occurred because of upload limitations. ...
2
by: Supermansteel | last post by:
I am joining these 2 tables together in Access 2003 and can't figure out the exact way of writing this script......Can anyone help? I have the following SQL: SELECT...
4
by: rhino | last post by:
I'm very new to XML and maybe just a touch impatient because I'm going to ask a moderately advanced question even though I'm just learning the basics. I've spent many years working with...
3
sumittyagi
by: sumittyagi | last post by:
Hi All, I am stuck with one tricky situation here. The situation is as follows:- I have two files, both files have two columns - space seperated key value pairs. Now say files are f1 and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.