开发者

How to convert html to doc in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 8 years ago.

Improve this question

I need to convert a html file to doc. I am using html2pdf for pdf conversion.

Is there is any same kind of library for html2doc?

(PS must be free/open source)

EDIT

After Mark Eirich comment..

Here are two screenshots. Word document is not proper aligned. Check y-scroll in word document. WORD document, check y scroll..

How to convert html to doc in php [closed]

Body tag is:--

<body style="margin-left:350px; margin-right:350px;">

I tried to adjust it but no effect..

EDIT 2

after Mark Eirich second comment i came to know word is taking things开发者_开发百科 in pixel not in %age.. I am having last issue of back ground.. Any help.. please check the two screen shots. The difference is outer box. and thats y html generated doc is looking odd.

How to convert html to doc in php [closed]

How to convert html to doc in php [closed]


The answer IMO Would be no, For the following reasons:

Microsoft Office Documents are extremely complex in the way they are designed, there not just a formatted file with references to objects such as images, there is a type od file system within itself to manage the binary data of these objects.

Let me bring in a quote from our very own Joel:

If you started reading these documents with the hope of spending a weekend writing some spiffy code that imports Word documents into your blog system, or creates Excel-formatted spreadsheets with your personal finance data, the complexity and length of the spec probably cured you of that desire pretty darn quickly. A normal programmer would conclude that Office’s binary file formats:

  • are deliberately obfuscated
  • are the product of a demented Borg mind
  • were created by insanely bad programmers
  • and are impossible to read or create correctly.

You’d be wrong on all four counts....

Read further down for a possible solution:

If you really want to generate fancy formatted Word documents, your best bet is to create an RTF document. Everything that Word can do can be expressed in RTF, but it’s a text format, not binary, so you can change things in the RTF document and it’ll still work. You can create a nicely formatted document with placeholders in Word, save as RTF, and then using simple text substitution, replace the placeholders on the fly. Now you have an RTF document that every version of Word will open happily.

@source: http://www.joelonsoftware.com/items/2008/02/19.html

Some links that may interest you along your journey:

  • Resources:
    • XHTML2RTF: An HTML to RTF conversion tool based on XSL
    • Word (.doc) Binary File Format
    • HTML+CSS to RTF (in PHP)?
  • Solutions
    • Live DOCX In PHP
    • Zend_Service_LiveDocx

Although, Try opening a word file with winrar ;), Maybe creating an archive with certain headers and then changing the extenstion will suffice, Never Tried


in order to convert to Microsoft Word you need an COM enabled server (running Windows and Office on it). If you have such a server

$word = new COM("word.application") or die ("couldnt create an instance of word"); 

should work!. Read http://php.net/manual/en/book.com.php for details.

Otherwise your best shot at html2doc is html2rtf which is achieved with a library such as http://paggard.com/projects/rtf.generator/ or http://sourceforge.net/projects/phprtf/.

Then after you create the RTF you serve it to the browser with a doc header

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

If the user has word then it will be open to handle the file.

Also saving an rtf as doc is ok and word will open in layout view without any complaints. You can also serve HTML with the above header but the problem is that Word will open in web view and that is bad :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜