PHP HTML to PDF conversion proportionally [closed]

泪湿孤枕 提交于 2019-12-01 13:32:36

问题


I am building a Web2Print website using PHP, MySQL and jQuery.The main concept of the website is the end users can create a HTML template by adding text, images, dragging, resizing etc dynamically and convert it to high-res A4 size PDF and then moves to printing.

For example see the link http://optisolbusiness.com/funeral_site/sample/index/id/255. This is the sample HTML that is to be converted to PDF. The width and height of the webpage HTML is 356x405px the problem is when I convert it to A4 PDFs size 8.5X11.69inches the HTML shows very small in PDF.

So I have to increase the width and height of the HTML to fit the PDF size, while increasing the HTML size to 8.5X11.69in. The content inside the HTML should also increase proportionally (ie) the text font size, background image, images width and height, top left should also be increased proportionally. The PDF should fit exactly like the HTML. I am using the online API htmlpdf.com to convert to PDF.


回答1:


How to do this? There are several approaches, but you must be willing to do your own research. You can paint PDFs in a variety of ways:

  • using graphics primitives in PHP libraries such as FPDF and TCPDF
  • using reporting software with document templates, such as JasperReports (requires server root access)
  • by converting from HTML, say via wkhtmltopdf (free) or Prince (expensive)
  • by manipulating SVG and rendering it to PDF, say in Inkscape (I've not seen other people taking this approach, but I have a working demo - see here. Only recommended if you are comfortable manipulating XML programmatically)

Remember that to get hi-res output (300-600pdi) on paper, you need to use proper fonts or vector graphics. These render at the resolution required, and won't pixellate if you use them properly. Failing this, use bitmaps at the correct resolution, so if you have a 1200px square image, and you wish to print at 600pdi, then the image cannot be larger than 2 inches either side.

In general it is best not to rely on third-party conversion services unless you have a contract with them - since they can take their site down or deny access at any time, and your work would be wasted.



来源:https://stackoverflow.com/questions/12834641/php-html-to-pdf-conversion-proportionally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!