forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CL_pdf.php
123 lines (95 loc) · 3.02 KB
/
CL_pdf.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?
//************************************************************************
// Leonardo XC Server, http://www.leonardoxc.net
//
// Copyright (c) 2004-2010 by Andreadakis Manolis
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// $Id: CL_pdf.php,v 1.1 2012/01/16 07:21:23 manolis Exp $
//
//************************************************************************
class leoPdf {
function leoPdf() {
}
function createPDF($url,$batchDir='',$forcedName=''){
global $CONF;
$hashkey=md5($url);
$tmpDir=$CONF['pdf']['tmpPath'].'/';
if ($batchDir) {
$batchDir=$batchDir.'/';
$tmpDir.=$batchDir;
}
$tmpFile=$hashkey.'.pdf';
if ($forcedName) $tmpFile=$forcedName;
@mkdir($tmpDir);
$cmd="cd $tmpDir; ".$CONF['pdf']['pdfcreator']." '$url' $tmpFile";
echo "createPDF: Will exec $cmd<BR>";
exec($cmd);
// echo "#######".$tmpDir.$tmpFile;
if (is_file($tmpDir.$tmpFile)) {
return $batchDir.$tmpFile;
} else {
return 0;
}
}
function createPDFmulti($urlArray,$batchDir){
global $CONF;
$i=1;
//do {
// $batchDir=rand(0,10000000);
//} while (is_dir($CONF['pdf']['tmpPath'].'/'.$batchDir)) ;
@mkdir($CONF['pdf']['tmpPath'].'/'.$batchDir);
$i=1;
//print_r($urlArray );
ksort($urlArray);
foreach($urlArray as $ii=>$url) {
$hashkey=md5($url);
$tmpFile=$CONF['pdf']['tmpPath'].'/'.$batchDir.'/'.sprintf("%05d",$i).'_'.$hashkey.'.pdf';
if( ! is_file($tmpFile)) {
$pdf=leoPDF::createPDF($url,$batchDir,sprintf("%05d",$i).'_'.$hashkey.'.pdf');
if ($pdf) $pdfFiles[]=$pdf;
} else {
$pdfFiles[]=$batchDir.'/'.sprintf("%05d",$i).'_'.$hashkey.'.pdf';
}
$i++;
}
// print_r($pdfFiles);
$filename=$CONF['pdf']['tmpPath'].'/'.$batchDir."/logbook.pdf";
if (is_file($filename)) {
echo "Final PDF already exists: $filename\n";
return $batchDir."/logbook.pdf";
}
if ($CONF['pdf']['pdftk']) {
$cmd=" cd ".$CONF['pdf']['tmpPath'].'/'.$batchDir." ; pdftk *.pdf cat output logbook.pdf";
// $cmd=" cd ".$CONF['pdf']['tmpPath']." ; gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf *.pdf";
echo "Will exec $cmd<BR>";
exec($cmd);
// print_r($out);
} else {
require_once dirname(__FILE__).'/lib/PDFMerger/PDFMerger.php';
$pdf = new PDFMerger;
foreach($pdfFiles as $pdfFile){
echo "Adding ".$CONF['pdf']['tmpPath'].'/'.$pdfFile."<br>\n";
$pdf->addPDF($CONF['pdf']['tmpPath'].'/'.$pdfFile, 'all');
}
//echo "now merging->\n";
$pdf->merge('file', $filename);
//echo "merged...\n";
}
/// echo "$filename\n";
if (is_file($filename)) {
// echo "loggobok $filename \n";
return $batchDir."/logbook.pdf";
} else {
return 0;
}
//foreach ($pdfFiles as $pdfFile) {
// echo "joining $pdfFile<BR>";
//}
// now join them
}
}
?>