0

I am trying to convert html to pdf using wkhtmltopdf but I am getting some funny output. When I am using through command prompt, the fonts are coming correctly but I am trying to execute that command in php using system, shell_exec and exec, its not taking correct font. What can be the issue?? One more thing I want to do is that I want to cut the pdf from the top of 20px something then make the pdf. Please help me if its possible to get by using wkhtmltopdf. I have tried many other converters which converts html to pdf but only wkhtmltopdf is giving the correct output. So please help me in only wkhtmltopdf. I can give you the link so that you can first try yourself first before reply.

My php script is the following, tell me if you can modify here itself.

$url = "http://raindrops.in/ainvvy/view/527a727a4251df44558b4567";

$blah = shell_exec("xvfb-run -a -s '-screen 0 1024x768x30' wkhtmltopdf -B 0 -L 0 -R 0 -T 0  --page-height 1147.8px --page-width 1800px --dpi 300 --encoding utf-8 ".$url." /tmp/test.pdf");
$a = file_get_contents("/tmp/test.pdf");
unlink("/tmp/test.pdf");
header('Content-Type: application/pdf');
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Length: '.strlen($a));
header('Content-Disposition: inline; filename="/tmp/test.pdf";');
echo $a;
die($a);
?>
Eric Herlitz
  • 23,976
  • 26
  • 110
  • 154
Rohit Singhal
  • 313
  • 1
  • 2
  • 17
  • To add 20px of space on top, just add `margin-top: 20px;` using CSS. As for fonts missing, it's an odd problem, but perhaps [encoding a font directly into CSS](http://stackoverflow.com/questions/6721295/google-web-fonts-and-pdf-generation-from-html-with-wkhtmltopdf/16204485#16204485) can help. – Arman H Jan 09 '14 at 18:44
  • Actually I want to remove top 20px of space from the top and margin-top will add the space. But still I tried this one using the options of --user-style-sheet in wkhtmltopdf and its not working, the space not adding in the top – Rohit Singhal Jan 10 '14 at 10:45

0 Answers0