Skip to content

Commit 132c64e

Browse files
committed
update examples
1 parent d8ab0a1 commit 132c64e

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

examples/pdml.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use pdml\PDML;
4+
5+
require '../vendor/autoload.php';
6+
7+
$PDML_AutoStart = isset($PDML_AutoStart)?$PDML_AutoStart:1; // Start PDF output automatically
8+
$PDML_FileName = isset($PDML_FileName)?$PDML_FileName:"doc.pdf"; // Default filename for PDF
9+
$PDML_Orientation = isset($PDML_Orientation)?$PDML_Orientation:"P"; // Orientation: P=Portrait / L=Landscape
10+
$PDML_Format = isset($PDML_Format)?$PDML_Format:"A4"; // Format: A3 / A4 / A5 / legal / letter
11+
12+
/*******************************************************************************
13+
* PDML to PDF conversion *
14+
* *
15+
* Parameters: *
16+
* buffer = pdml data *
17+
* Result: *
18+
* return = raw pdf data *
19+
* *
20+
*******************************************************************************/
21+
function pdml2pdf($buffer)
22+
{
23+
global $PDML_Orientation;
24+
global $PDML_Format;
25+
26+
$pdml = new PDML($PDML_Orientation,'pt',$PDML_Format);
27+
$pdml->compress=0;
28+
$pdml->ParsePDML($buffer);
29+
$s = $pdml->Output("","S");
30+
return ($s);
31+
}
32+
33+
/*******************************************************************************
34+
* Create and display PDF to STDOUT *
35+
* *
36+
* Parameters: *
37+
* buffer = pdml data *
38+
* Result: *
39+
* return = raw pdf data *
40+
* *
41+
*******************************************************************************/
42+
function ob_pdml($buffer)
43+
{
44+
global $PDML_FileName;
45+
46+
$s = pdml2pdf($buffer);
47+
48+
Header('Content-Type: application/pdf');
49+
Header('Content-Length: '.strlen($s));
50+
Header('Content-disposition: inline; filename='.$PDML_FileName);
51+
52+
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
53+
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
54+
header( "Cache-Control: no-cache, must-revalidate" );
55+
header( "Pragma: no-cache" );
56+
57+
return $s;
58+
}
59+
60+
// Start PDF ouput automatically is PDML_AutoStart is set
61+
if ($PDML_AutoStart) {
62+
ob_start("ob_pdml");
63+
}

0 commit comments

Comments
 (0)