Mercurial > pdfconcat
annotate pdfconcat.php @ 1:6ea97e3f7cb5 default tip
ignore log and upload, because they change in a live setup
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 29 Aug 2013 13:59:09 +0200 |
parents | 8f7e68d54c6d |
children |
rev | line source |
---|---|
0
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
1 <!-- |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
2 pdfconcat-0.1 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
3 Written by markus schnalke <meillo@marmaro.de>, |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
4 developed at KIT-Library, Karlsruhe. |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
5 This is free software under the CC0 license. |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
6 http://marmaro.de/prog/pdfconcat |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
7 --> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
8 <html> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
9 <head> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
10 <title>PDF concat and detextify</title> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
11 <meta name="author" content="markus schnalke <meillo@marmaro.de>"> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
12 <meta name="copyright" content="No copyright applies."> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
13 </head> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
14 <body> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
15 <h2>PDF concat and detextify</h2> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
16 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
17 <?php |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
18 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
19 define('PDFDETEXTIFY', dirname(__FILE__).'/bin/pdfdetextify'); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
20 define('PDFCONCAT', dirname(__FILE__).'/bin/pdfconcat'); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
21 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
22 define('LOGFILE', dirname(__FILE__).'/log'); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
23 define('UPLOADDIR', 'upload'); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
24 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
25 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
26 function |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
27 detextify($file) |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
28 { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
29 $newfile = tempnam(sys_get_temp_dir(), basename(__FILE__)."."); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
30 $cmd = sprintf("%s %s 2>&1 >%s", PDFDETEXTIFY, $file, $newfile); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
31 system($cmd); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
32 return $newfile; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
33 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
34 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
35 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
36 function |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
37 concatpdfs($files) |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
38 { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
39 $newfile = sprintf("%s/%s/%s.pdf", dirname(__FILE__), UPLOADDIR, |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
40 date('Y-m-d_H-i-s')); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
41 $cmd = sprintf("%s %s 2>&1 >%s", PDFCONCAT, implode(' ', $files), |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
42 $newfile); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
43 system($cmd); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
44 foreach ($files as $file) { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
45 unlink($file); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
46 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
47 return sprintf("%s/%s", UPLOADDIR, basename($newfile)); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
48 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
49 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
50 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
51 function |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
52 procfiles() |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
53 { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
54 $date = date("Y-m-d H:i:s"); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
55 $ip = $_SERVER['REMOTE_ADDR']; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
56 $files = array(); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
57 foreach ($_FILES as $key => $val) { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
58 if ($val['error'] == UPLOAD_ERR_NO_FILE) { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
59 continue; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
60 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
61 if ($val['error'] > 0) { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
62 echo "Errors in transferring $val[name]. Skipping.\n"; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
63 echo "($val[error])\n"; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
64 continue; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
65 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
66 if (isset($_POST[$key.'detextify']) && $_POST[$key.'detextify'] == 'on') { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
67 $files[] = detextify($val['tmp_name']); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
68 } else { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
69 $files[] = $val['tmp_name']; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
70 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
71 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
72 $newfile = concatpdfs($files); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
73 // log |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
74 $logmsg = sprintf("[%s] %s creates `%s'\n", $date, $ip, $newfile); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
75 file_put_contents(LOGFILE, $logmsg, FILE_APPEND); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
76 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
77 return $newfile; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
78 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
79 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
80 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
81 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
82 // main() |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
83 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
84 if (isset($_POST['submit'])) { |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
85 echo '<pre>'; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
86 $outfile = procfiles(); |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
87 echo '</pre>'; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
88 echo '<hr>'; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
89 echo '<h2><a href="'. $outfile .'">The concatenated PDF</a></h2>'; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
90 echo '<hr>'; |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
91 } |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
92 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
93 ?> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
94 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
95 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
96 <p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
97 This webservice concatenates PDF files and optionally converts their |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
98 text to bitmaps. |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
99 </p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
100 <p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
101 The files are stored temporary on the webserver. The detextification |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
102 function modifies them. Use this service only of you have the |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
103 appropriate rights on the files. |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
104 </p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
105 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
106 <form action="<?php echo basename($_SERVER['SCRIPT_NAME']); ?>" |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
107 method="post" enctype="multipart/form-data"> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
108 <p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
109 <input type="file" name="pdf1" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
110 detextify? <input type="checkbox" name="pdf1detextify" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
111 <br /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
112 <input type="file" name="pdf2" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
113 detextify? <input type="checkbox" name="pdf2detextify" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
114 <br /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
115 <input type="file" name="pdf3" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
116 detextify? <input type="checkbox" name="pdf3detextify" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
117 <br /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
118 <input type="file" name="pdf4" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
119 detextify? <input type="checkbox" name="pdf4detextify" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
120 <br /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
121 <input type="file" name="pdf5" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
122 detextify? <input type="checkbox" name="pdf5detextify" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
123 </p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
124 <p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
125 (Maximum file size: <?php echo ini_get('upload_max_filesize'); ?>) |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
126 </p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
127 <p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
128 <input type="submit" name="submit" /> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
129 </p> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
130 </form> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
131 |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
132 </body> |
8f7e68d54c6d
initial commit: should be already usable
markus schnalke <meillo@marmaro.de>
parents:
diff
changeset
|
133 </html> |