-
Notifications
You must be signed in to change notification settings - Fork 3
/
letterpdf.php
93 lines (79 loc) · 3.65 KB
/
letterpdf.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
<?php
/**************************************************************************\
* PHPAdvocat *
* http://phpadvocat.sourceforge.net *
* By Burkhard Obergoeker <[email protected]> *
* -------------------------------------------- *
* 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, or (at your *
* option) any later version. *
\**************************************************************************/
require("./include/phpadvocat.inc.php");
// require("./fpdf/fpdf.php");
/* Get User Account from Session Vars */
$user = $_SESSION["dbuser"];
$passwd = $_SESSION["dbpasswd"];
$changecheck="";
/* initialize database */
$db = new www_db;
$db->connect($user, $passwd);
if($_POST["latexfile"]) {
$latexfile = $_POST["latexfile"];
} elseif($_GET["latexfile"]) {
$latexfile = $_GET["latexfile"];
}
/* generate pdf file with latex system */
if(file_exists($latexfile) ) {
$fd=fopen($latexfile, "r");
$filecontent=fread($fd, filesize($latexfile));
fclose($fd);
$tempfilename = tempnam('', 'phpa-');
// echo "<hr>".$tempfilename."<hr>";
if($fd=fopen($tempfilename, "w")) {
fwrite($fd, $filecontent);
fclose($fd);
if($OSTYPE == 'UNIX')
system('./generatepdf.sh '.basename($tempfilename).' '.dirname($tempfilename).'>/dev/null');
if($OSTYPE == 'WINDOWS')
system('./generatepdf.sh '.basename($tempfilename).' '.dirname($tempfilename).'>/dev/null');
// printf('<hr> ./generatepdf.sh '.basename($tempfilename).' '.dirname($tempfilename).'<hr>');
if(file_exists($tempfilename.'.pdf')){
if($fd=fopen($tempfilename.'.pdf', "r")) {
$pdfcontent=fread($fd, filesize($tempfilename.'.pdf'));
fclose($fd);
$changecheck='PDF-Datei generiert';
//We send to a browser
header('Pragma: public');
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($pdfcontent));
// header('Content-disposition: inline; filename="'.$tmpfilename.'.pdf"');
header('Content-disposition: inline; filename="letter.pdf"');
echo $pdfcontent;
system('/bin/rm '.$tempfilename.'*');
exit;
} /* if open tempfilename.pdf */
} else { /* PDF file isn't there */
$changecheck='LaTeX Quelle fehlerhaft';
$fd=fopen($tempfilename.'.log', "r");
$logcontent=fread($fd, filesize($tempfilename.'.log'));
fclose($fd);
system('/bin/rm '.$tempfilename.'*');
} /* if exists tempfilename.pdf */
} else { /* Sourcefile not available */
$changecheck='Temporaere Datei konnte nicht erzeugt werden!';
} /* if open tempfilename.tex */
} else { /* latexfile don't exist */
$changecheck='LaTeX Quelle ('.$latexfile.') fehlt';
} /* endif file exists latexfile */
echo "<HEAD><TITLE>PHPAdvocat - PDF-Ausgabe</TITLE>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-15\"></HEAD>\n";
echo "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n";
echo "<TABLE width=100%><TR><TD>";
/* display Title */
echo "<CENTER><H1>Bearbeitung Rechnung</H1></CENTER><hr>\n";
echo "Die PDF-Erzeugung schlug fehl! Grund:<br>".$changecheck."<hr><b>Log:</b><br>";
echo str_ireplace(chr(10), '<br>', $logcontent);
/* End HTML PAGE */
echo "</td></tr></table></BODY></HTML>";
?>