This is an archived forum post. The information may be outdated. Contact us if you have any questions.
<?php $uploaddir = "files/"; //set this to where your files should be uploaded. Make sure to chmod to 777. if ($_FILES['file']) { $command = ""; foreach($_FILES['file']['type'] as $key => $value) { $ispdf = end(explode(".",$_FILES['file']['name'][$key])); //make sure it's a PDF file $ispdf = strtolower($ispdf); if ($value && $ispdf=='pdf') { //upload each file to the server $filename = $_FILES['file']['name'][$key]; $filename = str_replace(" ","",$filename); //remove spaces from file name $uploadfile = $uploaddir . $filename; move_uploaded_file($_FILES['file']['tmp_name'][$key], $uploadfile); // //build an array for the command being sent to output the merged PDF using pdftk $command = $command." files/".$filename; // } } $command = base64_encode($command); //encode and then decode the command string $command = base64_decode($command); $output = "files/merged-pdf".time().".pdf"; //set name of output file $command = "pdftk $command output $output"; passthru($command); //run the command header(sprintf('Location: %s', $output)); //open the merged pdf file in the browser } ?>
using RasterEdge.Imaging.Basic; using RasterEdge.Imaging.Basic.Core; using RasterEdge.Imaging.Basic.Codec; using RasterEdge.Imaging.PDF; namespace RE__Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static string FolderName = "c:/"; private void button1_Click(object sender, EventArgs e) { string fileName1 = FolderName + "Sample1.pdf"; string fileName2 = FolderName + "Sample2.pdf"; string fileNameMerged = FolderName + "Merged.pdf"; REDocument doc1 = REFile.OpenDocumentFile(fileName1, new PDFDecoder());//use PDFDecoder open one pdf file REDocument doc2 = REFile.OpenDocumentFile(fileName2, new PDFDecoder());//use PDFDecoder open another pdf file BaseDocument docMerged = doc1.MergeDocument(doc2);//merge two pdf REFile.SaveDocumentFile((REDocument)docMerged, fileNameMerged, new PDFEncoder());//save new pdf } } }