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