PHP HTML按比例转换为PDF [英] PHP HTML to PDF conversion proportionally

查看:121
本文介绍了PHP HTML按比例转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP,MySQL和jQuery构建Web2Print网站。网站的主要概念是最终用户可以通过动态添加文本,图像,拖动,调整大小等来创建HTML模板并将其转换为高分辨率A4大小的PDF,然后移动到打印。



例如,请参阅链接 http://optisolbusiness.com/funeral_site/sample/index/id/255
这是要转换为PDF的示例HTML。网页HTML的宽度和高度是356x405px问题是,当我将它转换为A4时,PDF文件大小为8.5X11.69英寸的HTML显示非常小的PDF。

所以,我必须增加HTML的宽度和高度以适应PDF大小,同时将HTML大小增加到8.5X11.69英寸。 HTML内的内容也应该按比例增加(即)文本字体大小,背景图像,图像宽度和高度,左上角也应按比例增加。 PDF应该完全符合HTML。
我使用在线API 转换为PDF。

解决方案

如何做到这一点?有几种方法,但你必须愿意做你自己的研究。您可以用多种方式绘制PDF:使用PHP库中的图形原语(如FPDF和TCPDF)



请记住,要在纸上获得高分辨率输出(300-600pdi),您需要使用正确的字体或矢量图形。这些以需要的分辨率进行渲染,并且如果正确使用它们将不会像素化。如果不这样做,请使用正确分辨率的位图,所以如果您有1200像素的正方形图像,并且您希望以600pdi进行打印,则图像不能大于2英寸。



一般来说,除非您与他们签有合约,否则最好不要依赖第三方转换服务 - 因为他们可以随时关闭网站或拒绝访问,并且您的工作将被浪费。


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.

解决方案

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.

这篇关于PHP HTML按比例转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆