PHP HTML按比例转换为PDF [英] PHP HTML to PDF conversion proportionally
问题描述
我使用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。
我使用在线API 转换为PDF。
如何做到这一点?有几种方法,但你必须愿意做你自己的研究。您可以用多种方式绘制PDF:使用PHP库中的图形原语(如FPDF和TCPDF)
-
- 使用带有文档模板的报告软件,例如JasperReports(需要服务器根访问)通过从HTML转换(例如通过
wkhtmltopdf $ c $)转换
- 通过操纵SVG并将其渲染为PDF,例如Inkscape(我还没有看到其他人正在采用这种方法,但我有一个工作方式,可以使用c>(免费)或Prince(昂贵)
- 演示 - 请参阅此处。仅当您以编程方式操作XML时才推荐)
请记住,要在纸上获得高分辨率输出(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屋!