HTML+CSS 到 RTF(在 PHP 中)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/605936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:14:11  来源:igfitidea点击:

HTML+CSS to RTF (in PHP)?

phphtmlcssrtf

提问by cletus

I am seeking a solution to converting HTML + CSS (2.1) to RTF in PHP. While I have found a superb solution for HTML to PDF in Prince XML, I've yet to find anything that:

我正在寻找将 HTML + CSS (2.1) 转换为 PHP 中的 RTF 的解决方案。虽然我在Prince XML 中找到了 HTML 到 PDF 的极好解决方案,但我还没有找到任何东西:

  • can convert HTML to RTF (or DOC);
  • runs on a Linux server;
  • is callable from PHP;
  • handles paged media and the ability to add page headers and footers; and
  • handles tables.
  • 可以将 HTML 转换为 RTF(或 DOC);
  • 在 Linux 服务器上运行;
  • 可从 PHP 调用;
  • 处理分页媒体和添加页眉和页脚的能力;和
  • 处理表。

Is there anything out there?

外面有什么吗?

回答by cletus

The easiest way to do this is using phpLiveDocx. It is component for the Zend Framework and completely free.

最简单的方法是使用phpLiveDocx。它是 Zend 框架的组件并且完全免费。

Supported template file formats (input)

支持的模板文件格式(输入)

  • DOCX - Microsoft Word DOCX Format
  • DOC - Microsoft Word DOC Format
  • RTF - Rich Text Format File
  • TXD - TX Text Control Format
  • DOCX - Microsoft Word DOCX 格式
  • DOC - Microsoft Word DOC 格式
  • RTF - 富文本格式文件
  • TXD - TX 文本控制格式

Supported document file formats (output)

支持的文档文件格式(输出)

  • DOCX - Microsoft Word DOCX Format
  • DOC - Microsoft Word DOC Format
  • RTF - Rich Text Format File
  • PDF - Acrobat Portable Document Format
  • TXD - TX Text Control Format
  • TXT - ANSI Plain Text
  • DOCX - Microsoft Word DOCX 格式
  • DOC - Microsoft Word DOC 格式
  • RTF - 富文本格式文件
  • PDF - Acrobat 便携式文档格式
  • TXD - TX 文本控制格式
  • TXT - ANSI 纯文本

From the project web site:

从项目网站:

"phpLiveDocx allows developers to generate documents by combining structured data from PHP with a template, created in a word processor. The resulting document can be saved as a PDF, DOCX, DOC or RTF file. The concept is the same as with mail-merge."

“phpLiveDocx 允许开发人员通过将来自 PHP 的结构化数据与在文字处理器中创建的模板相结合来生成文档。生成的文档可以保存为 PDF、DOCX、DOC 或 RTF 文件。其概念与邮件合并相同.”

For details, see:

有关详细信息,请参阅:

http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/

http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/

回答by vladr

For all your document conversion needs, you can use OpenOffice(running in headless mode.) You may invoke it with command-line parametersto perform conversion, or you may interface with itusing PUNO. You may spawn a new OpenOffice instance everytime you need conversion, or you may have one ore more instances run as daemon(s).

对于您所有的文档转换需求,您可以使用OpenOffice(在无头模式下运行)。您可以使用命令行参数调用它来执行转换,或者您可以使用PUNO与它交互。您可以在每次需要转换时生成一个新的 OpenOffice 实例,或者您可以将一个或多个实例作为守护程序运行。

With either interfacing choice, you will probably want to use a macro to add custom headers and footers after opening the html, but before exporting as Word.

无论选择哪种接口,您都可能希望在打开 html 之后、但在导出为 Word 之前使用宏添加自定义页眉和页脚。

回答by zfr

There is a PHP wrapper for HTML-to-PDF converter PD4ML. Optionally PD4ML can produce RTF instead of PDF. You just only need to add -outformat rtfor -outformat rtfwmfto its command line (and adjust HTTP header correspondingly).

HTML-to-PDF 转换器PD4ML有一个 PHP 包装器。PD4ML 可以选择生成RTF 而不是 PDF。您只需要在其命令行中添加-outformat rtf-outformat rtfwmf(并相应地调整 HTTP 标头)。