pdfconcat
diff pdfconcat.php @ 0:8f7e68d54c6d
initial commit: should be already usable
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 29 Aug 2013 13:58:17 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pdfconcat.php Thu Aug 29 13:58:17 2013 +0200 1.3 @@ -0,0 +1,133 @@ 1.4 +<!-- 1.5 + pdfconcat-0.1 1.6 + Written by markus schnalke <meillo@marmaro.de>, 1.7 + developed at KIT-Library, Karlsruhe. 1.8 + This is free software under the CC0 license. 1.9 + http://marmaro.de/prog/pdfconcat 1.10 +--> 1.11 +<html> 1.12 +<head> 1.13 +<title>PDF concat and detextify</title> 1.14 +<meta name="author" content="markus schnalke <meillo@marmaro.de>"> 1.15 +<meta name="copyright" content="No copyright applies."> 1.16 +</head> 1.17 +<body> 1.18 +<h2>PDF concat and detextify</h2> 1.19 + 1.20 +<?php 1.21 + 1.22 +define('PDFDETEXTIFY', dirname(__FILE__).'/bin/pdfdetextify'); 1.23 +define('PDFCONCAT', dirname(__FILE__).'/bin/pdfconcat'); 1.24 + 1.25 +define('LOGFILE', dirname(__FILE__).'/log'); 1.26 +define('UPLOADDIR', 'upload'); 1.27 + 1.28 + 1.29 +function 1.30 +detextify($file) 1.31 +{ 1.32 + $newfile = tempnam(sys_get_temp_dir(), basename(__FILE__)."."); 1.33 + $cmd = sprintf("%s %s 2>&1 >%s", PDFDETEXTIFY, $file, $newfile); 1.34 + system($cmd); 1.35 + return $newfile; 1.36 +} 1.37 + 1.38 + 1.39 +function 1.40 +concatpdfs($files) 1.41 +{ 1.42 + $newfile = sprintf("%s/%s/%s.pdf", dirname(__FILE__), UPLOADDIR, 1.43 + date('Y-m-d_H-i-s')); 1.44 + $cmd = sprintf("%s %s 2>&1 >%s", PDFCONCAT, implode(' ', $files), 1.45 + $newfile); 1.46 + system($cmd); 1.47 + foreach ($files as $file) { 1.48 + unlink($file); 1.49 + } 1.50 + return sprintf("%s/%s", UPLOADDIR, basename($newfile)); 1.51 +} 1.52 + 1.53 + 1.54 +function 1.55 +procfiles() 1.56 +{ 1.57 + $date = date("Y-m-d H:i:s"); 1.58 + $ip = $_SERVER['REMOTE_ADDR']; 1.59 + $files = array(); 1.60 + foreach ($_FILES as $key => $val) { 1.61 + if ($val['error'] == UPLOAD_ERR_NO_FILE) { 1.62 + continue; 1.63 + } 1.64 + if ($val['error'] > 0) { 1.65 + echo "Errors in transferring $val[name]. Skipping.\n"; 1.66 + echo "($val[error])\n"; 1.67 + continue; 1.68 + } 1.69 + if (isset($_POST[$key.'detextify']) && $_POST[$key.'detextify'] == 'on') { 1.70 + $files[] = detextify($val['tmp_name']); 1.71 + } else { 1.72 + $files[] = $val['tmp_name']; 1.73 + } 1.74 + } 1.75 + $newfile = concatpdfs($files); 1.76 + // log 1.77 + $logmsg = sprintf("[%s] %s creates `%s'\n", $date, $ip, $newfile); 1.78 + file_put_contents(LOGFILE, $logmsg, FILE_APPEND); 1.79 + 1.80 + return $newfile; 1.81 + 1.82 +} 1.83 + 1.84 + 1.85 +// main() 1.86 + 1.87 +if (isset($_POST['submit'])) { 1.88 + echo '<pre>'; 1.89 + $outfile = procfiles(); 1.90 + echo '</pre>'; 1.91 + echo '<hr>'; 1.92 + echo '<h2><a href="'. $outfile .'">The concatenated PDF</a></h2>'; 1.93 + echo '<hr>'; 1.94 +} 1.95 + 1.96 +?> 1.97 + 1.98 + 1.99 +<p> 1.100 + This webservice concatenates PDF files and optionally converts their 1.101 + text to bitmaps. 1.102 +</p> 1.103 +<p> 1.104 + The files are stored temporary on the webserver. The detextification 1.105 + function modifies them. Use this service only of you have the 1.106 + appropriate rights on the files. 1.107 +</p> 1.108 + 1.109 +<form action="<?php echo basename($_SERVER['SCRIPT_NAME']); ?>" 1.110 + method="post" enctype="multipart/form-data"> 1.111 +<p> 1.112 + <input type="file" name="pdf1" /> 1.113 + detextify? <input type="checkbox" name="pdf1detextify" /> 1.114 + <br /> 1.115 + <input type="file" name="pdf2" /> 1.116 + detextify? <input type="checkbox" name="pdf2detextify" /> 1.117 + <br /> 1.118 + <input type="file" name="pdf3" /> 1.119 + detextify? <input type="checkbox" name="pdf3detextify" /> 1.120 + <br /> 1.121 + <input type="file" name="pdf4" /> 1.122 + detextify? <input type="checkbox" name="pdf4detextify" /> 1.123 + <br /> 1.124 + <input type="file" name="pdf5" /> 1.125 + detextify? <input type="checkbox" name="pdf5detextify" /> 1.126 +</p> 1.127 +<p> 1.128 + (Maximum file size: <?php echo ini_get('upload_max_filesize'); ?>) 1.129 +</p> 1.130 +<p> 1.131 + <input type="submit" name="submit" /> 1.132 +</p> 1.133 +</form> 1.134 + 1.135 +</body> 1.136 +</html>