├── upload.php ├── download.min.js ├── style.css ├── process.php └── index.html /upload.php: -------------------------------------------------------------------------------- 1 | getFilename(), $prefix) === 0 && $file->getCTime() < $expireTime) { 10 | unlink($file->getPathname()); 11 | } 12 | } 13 | 14 | $fileUpload = tempnam(sys_get_temp_dir(), $prefix); 15 | header('Content-Type: application/json; charset=utf-8'); 16 | if (move_uploaded_file($_FILES['file']['tmp_name'], $fileUpload)) { 17 | echo '{"file": "' . explode("-", basename($fileUpload))[1] . '"}'; 18 | } else { 19 | http_response_code(500); 20 | echo '{"error": "UPLOAD_FAILED"}'; 21 | } 22 | 23 | ?> -------------------------------------------------------------------------------- /download.min.js: -------------------------------------------------------------------------------- 1 | //download.js v4.21, by dandavis; 2008-2018. [MIT] see http://danml.com/download.html for tests/usage 2 | ;(function(root,factory){typeof define=="function"&&define.amd?define([],factory):typeof exports=="object"?module.exports=factory():root.download=factory()})(this,function(){return function download(data,strFileName,strMimeType){var self=window,defaultMime="application/octet-stream",mimeType=strMimeType||defaultMime,payload=data,url=!strFileName&&!strMimeType&&payload,anchor=document.createElement("a"),toString=function(a){return String(a)},myBlob=self.Blob||self.MozBlob||self.WebKitBlob||toString,fileName=strFileName||"download",blob,reader;myBlob=myBlob.call?myBlob.bind(self):Blob,String(this)==="true"&&(payload=[payload,mimeType],mimeType=payload[0],payload=payload[1]);if(url&&url.length<2048){fileName=url.split("/").pop().split("?")[0],anchor.href=url;if(anchor.href.indexOf(url)!==-1){var ajax=new XMLHttpRequest;return ajax.open("GET",url,!0),ajax.responseType="blob",ajax.onload=function(e){download(e.target.response,fileName,defaultMime)},setTimeout(function(){ajax.send()},0),ajax}}if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(payload)){if(!(payload.length>2096103.424&&myBlob!==toString))return navigator.msSaveBlob?navigator.msSaveBlob(dataUrlToBlob(payload),fileName):saver(payload);payload=dataUrlToBlob(payload),mimeType=payload.type||defaultMime}else if(/([\x80-\xff])/.test(payload)){var i=0,tempUiArr=new Uint8Array(payload.length),mx=tempUiArr.length;for(i;i0?3:2,decoder=parts[indexDecoder]=="base64"?atob:decodeURIComponent,binData=decoder(parts.pop()),mx=binData.length,i=0,uiArr=new Uint8Array(mx);for(i;i $maxPages - $pages) { 33 | $end = $start + ($maxPages - $pages); 34 | $pages = $maxPages; 35 | $newRanges[] = $begin . "-" . $end; 36 | } else { 37 | $newRanges[] = $r; 38 | $pages += $pagesInRange; 39 | } 40 | } 41 | 42 | if ($pages === $maxPages) { 43 | break; 44 | } 45 | } 46 | 47 | return join(",", $newRanges); 48 | } 49 | 50 | function error($reason) { 51 | header('Content-Type: application/json; charset=utf-8'); 52 | http_response_code(500); 53 | echo '{"error":"' . $reason . '"}'; 54 | exit; 55 | } 56 | 57 | 58 | 59 | if (!isset($_POST['settings'])) { 60 | error("SETTINGS_MISSING"); 61 | } 62 | 63 | $settings = json_decode($_POST['settings'], true); 64 | if (!$settings) { 65 | error("SETTINGS_DECODE_ERROR"); 66 | } 67 | 68 | if (!isset($settings['file']) || empty($settings['file'])) { 69 | error("SETTINGS_MISSING_FILE_PARAM"); 70 | } 71 | 72 | $dir = sys_get_temp_dir(); 73 | $file = $dir . DIRECTORY_SEPARATOR . "Upload-" . $settings['file']; 74 | if ($settings['preview']) { 75 | $suffix = "preview"; 76 | } else { 77 | $suffix = "final"; 78 | } 79 | 80 | $options = array( 81 | "pdfjam", 82 | "--vanilla", 83 | "--checkfiles", 84 | "--outfile", 85 | $dir, 86 | "--suffix", 87 | $suffix, 88 | "--keepinfo" 89 | ); 90 | 91 | // nup 92 | $nup = 1; 93 | if (isset($settings['xnup']) && is_numeric($settings['xnup']) 94 | && isset($settings['ynup']) && is_numeric($settings['ynup'])) { 95 | $options[] = "--nup"; 96 | $options[] = $settings['xnup'] . "x" . $settings['ynup']; 97 | $nup = $settings['xnup'] * $settings['ynup']; 98 | } 99 | 100 | // landscape 101 | if ($settings['landscape']) { 102 | $options[] = "--landscape"; 103 | } else { 104 | $options[] = "--no-landscape"; 105 | } 106 | 107 | // paper / papersize 108 | if (isset($settings['paper']) && !empty($settings['paper'])) { 109 | $paper = strtolower($settings['paper']); 110 | if (preg_match("/^(?:[abc][0-6]|letter|legal)$/m", $paper)) { 111 | $options[] = "--paper"; 112 | $options[] = $paper . "paper"; 113 | } 114 | } else if (isset($settings['xpapersize']) && isLatexUnit($settings['xpapersize']) 115 | && isset($settings['ypapersize']) && isLatexUnit($settings['ypapersize'])) { 116 | $options[] = "--papersize"; 117 | $options[] = "'{" . $settings['xpapersize'] . "," . $settings['ypapersize'] . "}'"; 118 | } 119 | 120 | $options[] = "--"; 121 | 122 | // input file 123 | $options[] = $file; 124 | 125 | // page range 126 | if (isset($settings['pages']) && !empty($settings['pages'])) { 127 | $pages = preg_replace("/[^\d,_-]/m", "", $settings['pages']); 128 | } else { 129 | $pages = "-"; 130 | } 131 | if (preg_match("/((?:\d*-\d*|\d+|_)(?:,(?:\d*-\d*|\d+|_))*)/m", $pages, $matches)) { 132 | if ($settings['preview']) { 133 | // reduce page range 134 | $maxPages = exec("pdfinfo " . $file . " | awk '/^Pages:/ {print $2}'"); 135 | $pages = reducePageRange($matches[0], $nup, $maxPages); 136 | } 137 | 138 | $options[] = "'" . str_replace("_", "{}", $pages) . "'"; 139 | } else { 140 | error("SETTINGS_PAGES_PARAM_ERROR"); 141 | } 142 | 143 | // capture full console output 144 | $options[] = "2>&1"; 145 | 146 | $cmd = join(" ", $options); 147 | 148 | // debug 149 | if ($settings['debug']) { 150 | echo $cmd; 151 | exit; 152 | } 153 | 154 | $output = exec($cmd); 155 | // echo "
" . $cmd . "

output first call

";
156 | // print_r($output);
157 | // echo "
"; 158 | 159 | if (!$output) { 160 | error("CONVERSION_FAILED"); 161 | } 162 | 163 | if (!preg_match("/^ pdfjam: Finished. Output was written to '(\S+)'.$/m", $output, $matches) 164 | || !file_exists($matches[1])) { 165 | error("CONVERSION_FAILED"); 166 | } 167 | 168 | if ($settings['reverse'] && !$settings['preview']) { 169 | $options = array( 170 | "pdfjam", 171 | "--vanilla", 172 | "--checkfiles", 173 | "--outfile", 174 | $dir, 175 | "--suffix", 176 | "reversed", 177 | "--keepinfo", 178 | "--", 179 | $matches[1], 180 | "'last-1'", 181 | "2>&1" 182 | ); 183 | $cmd = join(" ", $options); 184 | $output = exec($cmd); 185 | // $res = exec($cmd, $output, $result); 186 | // echo "
" . $cmd . "

output second call, result" . $result . " " . $res . "

";;
187 |     // print_r($output);
188 |     // echo "
"; 189 | // exit; 190 | 191 | if (!$output) { 192 | error("INVERSION_FAILED1"); 193 | } 194 | if (!preg_match("/^ pdfjam: Finished. Output was written to '(\S+)'.$/m", $output, $matches) 195 | || !file_exists($matches[1])) { 196 | error("INVERSION_FAILED2"); 197 | } 198 | } 199 | 200 | header('Content-Type: application/octet-stream'); 201 | header('Content-Length: ' . filesize($matches[1])); 202 | readfile($matches[1]); 203 | 204 | ?> -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PDF Jam 7 | 8 | 9 | 10 | 11 | 12 | 13 | 370 | 371 | 372 | 373 | 374 | 375 |
376 |
PDF hier ablegen
377 |
378 |
379 |
380 |
381 | 382 | 386 | 387 | 388 | 389 |
390 | 391 |
392 |
393 | Beispiele: 394 |

- = alle Seiten

395 |

4- = ab Seite 4 bis Ende

396 |

-5 = von Seite 1 bis 5

397 |

_ = leere Seite einfügen

398 |

1-5,9-10 = Seitenbereiche 1-5 und 9-10

399 |

1,1,1,5- = 3x Seite 1 und ab Seite 5 bis Ende

400 |
401 |
402 | 403 |
404 | 405 | 406 | 415 |
416 |
417 | 418 | 419 |
420 | × 421 |
422 |
423 | 424 | 425 |
426 | 427 |
428 |
Vorschau
429 |
430 | 431 | 434 | 435 |
436 |
Herunterladen
437 |
438 | 439 | 440 | 441 | --------------------------------------------------------------------------------