-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
35 lines (28 loc) · 958 Bytes
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once('overlay.php');
$json = json_decode($_POST['json'], true);
$prefix = "/tmp/webform";
$pages = "";
$output = $prefix.'-new.pdf';
// overlay all pages
for ($page=0; $page<sizeof($json); $page++)
{
$original = $prefix.'-'.$page.'-original.pdf';
$overlay = $prefix.'-'.$page.'-overlay.pdf';
$result = $prefix.'-'.$page.'.pdf';
exec('pdftk '.$prefix.'.pdf cat '.$page.' output '.$original);
overlay($json[$page], $overlay);
exec('pdftk '.$original.' stamp '.$overlay.' output '.$result);
$pages .= " ".$result;
}
// concatenate all pages
exec('pdftk '.$pages.' cat output '.$output);
// return created PDF
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header("Cache-Control: public");
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($output));
header("Content-Disposition: attachment; filename=webform.pdf");
readfile($output);
?>