HTML+CSS to RTF (in PHP)?
Asked Answered
W

3

18

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:

  • 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.

Is there anything out there?

Woodshed answered 3/3, 2009 at 10:54 Comment(5)
If only it wasn't $4000~ for a server license!Gus
Mind sharing what you ended up using?Blackheart
@meder I never really found a good solution for this. In the end the requirement went away so it became a non-issue.Woodshed
html2pdf was a good library for html to pdf conversion. I am looking for same for htmlToDoc /DOCx/ rtf???Shaner
Haven't looked through thoroughly, but w3.org/Tools/html2things.html may be of interestSansbury
A
13

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

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

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

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."

For details, see:

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

Apartheid answered 14/5, 2009 at 6:56 Comment(1)
Maybe I am missing something, but liveDocX doesn't support HTML as input. Is this correct?Foothill
T
12

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

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.

Teepee answered 5/3, 2009 at 2:56 Comment(0)
T
1

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 rtf or -outformat rtfwmf to its command line (and adjust HTTP header correspondingly).

Tody answered 10/7, 2013 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.