| 1 |
lars |
1 |
<?php
|
|
|
2 |
require_once('../config.inc.php');
|
|
|
3 |
require_once('../pipeline.factory.class.php');
|
|
|
4 |
parse_config_file('../html2ps.config');
|
|
|
5 |
|
|
|
6 |
function convert_to_pdf($pdf) {
|
|
|
7 |
|
|
|
8 |
class MyDestinationFile extends Destination {
|
|
|
9 |
var $_dest_filename;
|
|
|
10 |
|
|
|
11 |
function MyDestinationFile($dest_filename) {
|
|
|
12 |
$this->_dest_filename = $dest_filename;
|
|
|
13 |
}
|
|
|
14 |
|
|
|
15 |
function process($tmp_filename, $content_type) {
|
|
|
16 |
copy($tmp_filename, $this->_dest_filename);
|
|
|
17 |
}
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
class MyDestinationDownload extends DestinationHTTP {
|
|
|
22 |
function MyDestinationDownload($filename) {
|
|
|
23 |
$this->DestinationHTTP($filename);
|
|
|
24 |
$GLOBALS['PDFOutFileName'] = $filename;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
function headers($content_type) {
|
|
|
28 |
return array(
|
|
|
29 |
"Content-Disposition: attachment; filename=".$GLOBALS['PDFOutFileName'].".".$content_type->default_extension,
|
|
|
30 |
"Content-Transfer-Encoding: binary",
|
|
|
31 |
"Cache-Control: must-revalidate, post-check=0, pre-check=0",
|
|
|
32 |
"Pragma: public"
|
|
|
33 |
);
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
class MyFetcherLocalFile extends Fetcher {
|
|
|
38 |
var $_content;
|
|
|
39 |
|
|
|
40 |
function MyFetcherLocalFile() {
|
|
|
41 |
$this->_content = "Test<!--NewPage-->Test<pagebreak/>Test<?page-break>Test";
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
function get_data($dummy1) {
|
|
|
45 |
return new FetchedDataURL($this->_content, array(), "");
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
function get_base_url() {
|
|
|
49 |
return "";
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
$media = Media::predefined("A4");
|
|
|
56 |
$media->set_landscape(false);
|
|
|
57 |
$media->set_margins(array('left' => 0,
|
|
|
58 |
'right' => 0,
|
|
|
59 |
'top' => 0,
|
|
|
60 |
'bottom' => 0));
|
|
|
61 |
$media->set_pixels(1024);
|
|
|
62 |
|
|
|
63 |
$GLOBALS['g_config'] = array(
|
|
|
64 |
'cssmedia' => 'screen',
|
|
|
65 |
'renderimages' => true,
|
|
|
66 |
'renderforms' => false,
|
|
|
67 |
'renderlinks' => true,
|
|
|
68 |
'renderfields' => true,
|
|
|
69 |
'mode' => 'html',
|
|
|
70 |
'debugbox' => false,
|
|
|
71 |
'draw_page_border' => false,
|
|
|
72 |
);
|
|
|
73 |
|
|
|
74 |
$g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels;
|
|
|
75 |
$g_pt_scale = $g_px_scale * 1.43;
|
|
|
76 |
|
|
|
77 |
$pipeline = new Pipeline;
|
|
|
78 |
$pipeline->configure($GLOBALS['g_config']);
|
|
|
79 |
$pipeline->fetchers[] = new MyFetcherLocalFile();
|
|
|
80 |
// $pipeline->destination = new MyDestinationFile($pdf);
|
|
|
81 |
$pipeline->destination = new MyDestinationDownload($pdf);
|
|
|
82 |
$pipeline->data_filters[] = new DataFilterHTML2XHTML;
|
|
|
83 |
$pipeline->pre_tree_filters = array();
|
|
|
84 |
$header_html = "test";
|
|
|
85 |
$footer_html = "test";
|
|
|
86 |
$filter = new PreTreeFilterHeaderFooter($header_html, $footer_html);
|
|
|
87 |
$pipeline->pre_tree_filters[] = $filter;
|
|
|
88 |
$pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields();
|
|
|
89 |
$pipeline->parser = new ParserXHTML();
|
|
|
90 |
$pipeline->layout_engine = new LayoutEngineDefault;
|
|
|
91 |
$pipeline->output_driver = new OutputDriverFPDF($media);
|
|
|
92 |
|
|
|
93 |
$pipeline->process('', $media);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
convert_to_pdf("test");
|
|
|
97 |
?>
|