从PHP文件生成的XML获取PDF输出并使用XSLT进行翻译

时间:2022-12-28 09:48:58

I've used a couple of days to think of a best practice to generate a PDF, which end users can customize the layout for themselves. The PDF output needs to be saved on the server or sent back to the PHP file so the PHP file can save it, and the PHP file needs to know that it went OK.

我用了几天时间来思考生成PDF的最佳实践,最终用户可以自己定制布局。 PDF输出需要保存在服务器上或发送回PHP文件,以便PHP文件可以保存它,PHP文件需要知道它正常。

I thought the best way to do this was to use XML, XSLT and Apache Cocoon. But I'm not sure if this is possible or if it's a good idea since I can't find any information of people doing anything similar. It cannot be an uncommon problem.

我认为最好的方法是使用XML,XSLT和Apache Cocoon。但是我不确定这是否可能,或者这是一个好主意,因为我找不到任何人做类似事情的信息。这不是一个不常见的问题。

The idea came when I read about Cocoon converting XML through XSLT to PDF:

当我读到关于通过XSLT将XML转换为PDF的Cocoon时,我就想到了这个想法:

http://cocoon.apache.org/2.1/howto/howto-html-pdf-publishing.html

http://cocoon.apache.org/2.1/howto/howto-html-pdf-publishing.html

and being able to take in variables:

并且能够接受变量:

http://old.nabble.com/how-to-access-post-parameters-from-sitemap-td31478752.html

http://old.nabble.com/how-to-access-post-parameters-from-sitemap-td31478752.html

This is what I had in mind:

这就是我的想法:

  1. A php file gets called by a user, the php file generates a source XML file with a specific name
  2. php文件由用户调用,php文件生成具有特定名称的源XML文件
  3. The php file then makes a request to Cocoon (on the same web server) to apply the user defined XSLT on the XML file. A parameter will be needed here to know which XSLT to apply.
  4. 然后,php文件向Cocoon(在同一Web服务器上)发出请求,以在XML文件上应用用户定义的XSLT。这里需要一个参数来知道要应用哪个XSLT。
  5. The request is handled by the PHP file and then saved as a PDF on the server, and can later be mailed away.
  6. 该请求由PHP文件处理,然后在服务器上保存为PDF,以后可以邮寄。

Will this work at all? Is there a better way to handle this?

这有用吗?有没有更好的方法来处理这个?

The core problem is that the users need to be able to customize the layout on the PDFs themselves, and I need the server to save the PDF and to mail it later on. The users will use it for order confirmations, invoices, etc. And I wouldn't like to hard code the layout for each user.

核心问题是用户需要能够自定义PDF本身的布局,我需要服务器保存PDF并稍后将其邮寄。用户将使用它来进行订单确认,发票等。我不想为每个用户硬编码布局。

2 个解决方案

#1


0  

I've had some good results in the past by setting up JasperReports Server and creating reports using iReport Designer. They're both available in F/OSS ("community") editions, though you can pay for support and value-adds if you need those things.

过去,我通过设置JasperReports Server并使用iReport Designer创建报告,取得了一些不错的成绩。它们都可以在F / OSS(“社区”)版本中使用,但如果您需要这些东西,您可以支付支持和增值。

This was a good solution for us, since we could access it via the Java API for our Java system, and via SOAP for our PHP system. The GUI designer made tweaking reports very easy for non-technical business staff too.

这对我们来说是一个很好的解决方案,因为我们可以通过Java API为我们的Java系统访问它,也可以通过SOAP访问我们的PHP系统。 GUI设计师也非常容易地为非技术业务人员提供调整报告。

#2


0  

I use webkithtml2pdf to generate my PDF:s. Just create a document with HTML and CSS for printing like you would usually do, the run it through the converter.

我使用webkithtml2pdf生成我的PDF:s。只需创建一个包含HTML和CSS的文档,就像您通常所做的那样,通过转换器运行它。

It works great for generating things like invoices. You can use SVG for logos and illustrations, and they will look great in print since they are vector based. Even rounded corners with dotted outlines works perfectly.

它非常适合生成发票等内容。您可以将SVG用于徽标和插图,因为它们是基于矢量的,所以它们在打印时看起来很棒。即使是带有虚线轮廓的圆角也能完美呈现。

A minor gotcha is that the input html must have th htm or html file name suffix, so you can't use the default tempfile functions.

一个小问题是输入html必须有htm或html文件名后缀,所以你不能使用默认的tempfile函数。

#1


0  

I've had some good results in the past by setting up JasperReports Server and creating reports using iReport Designer. They're both available in F/OSS ("community") editions, though you can pay for support and value-adds if you need those things.

过去,我通过设置JasperReports Server并使用iReport Designer创建报告,取得了一些不错的成绩。它们都可以在F / OSS(“社区”)版本中使用,但如果您需要这些东西,您可以支付支持和增值。

This was a good solution for us, since we could access it via the Java API for our Java system, and via SOAP for our PHP system. The GUI designer made tweaking reports very easy for non-technical business staff too.

这对我们来说是一个很好的解决方案,因为我们可以通过Java API为我们的Java系统访问它,也可以通过SOAP访问我们的PHP系统。 GUI设计师也非常容易地为非技术业务人员提供调整报告。

#2


0  

I use webkithtml2pdf to generate my PDF:s. Just create a document with HTML and CSS for printing like you would usually do, the run it through the converter.

我使用webkithtml2pdf生成我的PDF:s。只需创建一个包含HTML和CSS的文档,就像您通常所做的那样,通过转换器运行它。

It works great for generating things like invoices. You can use SVG for logos and illustrations, and they will look great in print since they are vector based. Even rounded corners with dotted outlines works perfectly.

它非常适合生成发票等内容。您可以将SVG用于徽标和插图,因为它们是基于矢量的,所以它们在打印时看起来很棒。即使是带有虚线轮廓的圆角也能完美呈现。

A minor gotcha is that the input html must have th htm or html file name suffix, so you can't use the default tempfile functions.

一个小问题是输入html必须有htm或html文件名后缀,所以你不能使用默认的tempfile函数。