58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
class Merge_pdf extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function merge()
|
|
{
|
|
$param = $this->sys_input;
|
|
$target = tempnam("/tmp", uniqid("target", true));
|
|
$merge_cmd = "/usr/bin/pdfunite";
|
|
$base_url = "http://localhost/";
|
|
$fnames_del = [];
|
|
$origin = $param["input"];
|
|
$dob = $param["dob"];
|
|
$output_file_name = $param["output"];
|
|
foreach ($origin as $r) {
|
|
$fname = tempnam("/tmp", uniqid("src", true));
|
|
$rpt_data = file_get_contents($r);
|
|
if (strlen($rpt_data) > 0) {
|
|
file_put_contents($fname, $rpt_data);
|
|
$merge_cmd .= " $fname ";
|
|
}
|
|
$fnames_del[] = $fname;
|
|
}
|
|
$merge_cmd .= " $target";
|
|
$output = [];
|
|
exec($merge_cmd, $output);
|
|
if ($dob != "") {
|
|
$target_enc = tempnam("/tmp", uniqid("targetenc", true));
|
|
$enc_cmd = "/usr/bin/pdftk $target output $target_enc user_pw $dob";
|
|
exec($enc_cmd, $output);
|
|
}
|
|
header("Content-type: application/pdf");
|
|
header(
|
|
'Content-Disposition: inline; filename="' .
|
|
$output_file_name .
|
|
'"'
|
|
);
|
|
if ($dob != "") {
|
|
echo file_get_contents($target_enc);
|
|
} else {
|
|
echo file_get_contents($target);
|
|
}
|
|
foreach ($fnames_del as $fdel) {
|
|
unlink($fdel);
|
|
}
|
|
if (file_exists($target)) {
|
|
unlink($target);
|
|
}
|
|
if ($dob != "" && file_exists($target_enc)) {
|
|
unlink($target_enc);
|
|
}
|
|
exit;
|
|
}
|
|
}
|