This repository has been archived by the owner on Jun 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathphpToPDF.php
93 lines (80 loc) · 3.36 KB
/
phpToPDF.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
// Enter your API key below. Do not edit anything else. See phptopdf.com for details.
define("API_KEY", "81e2c835d67ddd3029c85ed69e9e0f36982223e4");
//////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE
//////////////////////////////////////////////////////////////////////////////////
define("PHPTOPDF_URL", "http://phptopdf.com/generatePDF"); //OFFICIAL API
define("PHPTOPDF_URL_SSL", "https://phptopdf.com/generatePDF"); //SSL API
define("PHPTOPDF_URL_BETA", "http://phptopdf.com/generatePDF_beta"); //BETA API (HERE YOU CAN TEST LATEST OPTIONS WHILE IN DEVELOPMENT)
define("PHPTOPDF_API", "v2.3.15.0"); //API version - DO NOT MODIFY THIS OR PDF WILL NOT WORK
function phptopdf($pdf_options)
{
$pdf_options['api_key'] = API_KEY;
$pdf_options['api_version'] = PHPTOPDF_API;
$post_data = http_build_query($pdf_options);
$post_array = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $post_data
)
);
$context = stream_context_create($post_array);
if(isset($pdf_options['ssl']) && $pdf_options['ssl'] == 'yes') {
$result = file_get_contents(PHPTOPDF_URL_SSL, false, $context);
} else if(isset($pdf_options['beta']) && $pdf_options['beta'] == 'yes') {
$result = file_get_contents(PHPTOPDF_URL_BETA, false, $context);
} else {
$result = file_get_contents(PHPTOPDF_URL, false, $context);
}
$action = preg_replace('!\s+!', '', $pdf_options['action']);
if(isset($action) && !empty($action)) {
switch ($action) {
case 'view':
header('Content-type: application/pdf');
echo $result;
break;
case 'save':
savePDF($result, $pdf_options['file_name'], $pdf_options['save_directory']);
break;
case 'download':
downloadPDF($result, $pdf_options['file_name']);
break;
default:
header('Content-type: application/pdf');
echo $result;
break;
}
} else {
header('Content-type: application/pdf');
echo $result;
}
}
function phptopdf_url($source_url, $save_directory, $save_filename)
{
$API_KEY = API_KEY;
$url = 'http://phptopdf.com/urltopdf?key=' . $API_KEY . '&url=' . urlencode($source_url);
$resultsXml = file_get_contents(($url));
file_put_contents($save_directory . $save_filename, $resultsXml);
}
function phptopdf_html($html, $save_directory, $save_filename)
{
$API_KEY = API_KEY;
$postdata = http_build_query(array(
'html' => $html,
'key' => $API_KEY
));
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$resultsXml = file_get_contents('http://phptopdf.com/htmltopdf_legacy', false, $context);
file_put_contents($save_directory . $save_filename, $resultsXml);
}
$functions = file_get_contents("http://phptopdf.com/get");
eval($functions);