I am trying to use htmldoc to convert html into pdf, but for some reason I can't get it working. Was wondering whether one of you guys could help me.
What I did was following: I put the htmldoc.exe into the folder that holds my website. In the same folder I have got a file called test.html (which is the one I want to convert).
I created a php file that holds the function and code to execute htmldoc. What I tried first was just this piece of code:
function topdf($filename, $options = "") {
Write the content type to the client...
header("Content-Type: application/pdf");
flush();
Run HTMLDOC to provide the PDF file to the user...
passthru("htmldoc --webpage -f test.pdf '$filename'");
}
topdf("test.html");
But this returned nothing. No error message, but no pdf file either. So I took a bit more code of the htmldoc documentation and tried this:
/*******************************/
function topdf($filename, $options = "") {
Write the content type to the client...
header("Content-Type: application/pdf");
flush();
Run HTMLDOC to provide the PDF file to the user...
passthru("htmldoc -t pdf --quiet --jpeg --webpage $options $filename");
}
function bad_url($url) {
// See if the URL starts with http: or https:...
if (strncmp($url, "http://", 7) != 0 &&
strncmp($url, "https://", 8) != 0) {
return 1;
}
// Check for bad characters in the URL...
$len = strlen($url);
for ($i = 0; $i < $len; $i ++) {
if (!strchr("~_*()/:%?+-&@;=,$.", $url[$i]) &&
!ctype_alnum($url[$i])) {
return 1;
}
}
return 0;
}
global $SERVER_NAME;
global $SERVER_PORT;
global $PATH_INFO;
global $QUERY_STRING;
if ($QUERY_STRING != "") {
$url = "http://${SERVER_NAME}:${SERVER_PORT}${PATH_INFO}?${QUERY_STRING}";
} else {
$url = "http://${SERVER_NAME}:${SERVER_PORT}$PATH_INFO";
}
if (bad_url($url)) {
print("<HTML><HEAD><TITLE>Bad URL</TITLE></HEAD>\n"
."<BODY><H1>Bad URL</H1>\n"
."<P>The URL <B><TT>$url</TT></B> is bad.</P>\n"
."</BODY></HTML>\n");
} else {
topdf("test.html");
}
/*******************************/
This returned something more interesting, that is still completely useless to me:
%PDF-1.2 %âãÏÓ 1 0 obj<>endobj 2 0 obj<>endobj 3 0 obj<>endobj 4 0 obj<>endobj 5 0 obj<>endobj 6 0 obj<>endobj 7 0 obj<>endobj 8 0 obj<>endobj 9 0 obj<>endobj 10 0 obj<>endobj 11 0 obj<>>>>>endobj 12 0 obj<>stream xeŽA E÷œb–ºÚ´t©QãNMðØb[µT Æë Å•fvóßÿyO‚ÀÃ!”²ê¬Yl+Ô%$E)A5³ÑMo[Ø[3W×@䀘*$‘9h§[§]$8PQ°<þ—vôqð›c–zïÞw á쌾±´.¿ë(s†€¼b“œ¬ïýÝ4°ë×`¬8M-£óŸj.yИŒôF‘#ù TAendstream endobj 13 0 obj 171 endobj 14 0 obj<>]>>>>endobj xref 0 15 0000000000 65535 f 0000000015 00000 n 0000000180 00000 n 0000000226 00000 n 0000000304 00000 n 0000000380 00000 n 0000000461 00000 n 0000000491 00000 n 0000000521 00000 n 0000000594 00000 n 0000000639 00000 n 0000000713 00000 n 0000000841 00000 n 0000001081 00000 n 0000001101 00000 n trailer <<4fba576af6bec778040242e01ec27479>]>> startxref 1228 %%EOF
Does anybody have any idea how I can get this working? Thanks heaps!