Page 1 of 1
Convert Html/PHP with external css to MS Word file
Posted: Fri Dec 02, 2016 3:00 pm
by altabmw01
Hi All,
I need convert HTML/PHP with external css to MS Word file. I have a php file which is design by external css and i need to convert it in MS word docx file. How to get the proper solution for this problem. I am using PHPWORD script but it's work for basic html and css but not working with external css. If you have any solution, please help me with that.
Thanks
Altab Hossen
Re: Convert Html/PHP with external css to MS Word file
Posted: Fri Dec 02, 2016 3:02 pm
by Christopher
Have you tried pasting the stylesheet inline instead of an external link?
Re: Convert Html/PHP with external css to MS Word file
Posted: Fri Dec 02, 2016 3:14 pm
by altabmw01
Yes but not working #Christopher
Re: Convert Html/PHP with external css to MS Word file
Posted: Fri Dec 02, 2016 6:36 pm
by Christopher
So your CSS is not working at all? Or certain styles are not working?
And, have to tried just selecting the whole page in the browser, copying it and pasting it into Word?
Re: Convert Html/PHP with external css to MS Word file
Posted: Fri Dec 02, 2016 6:54 pm
by thinsoldier
altabmw01 wrote:Hi All,
I need convert HTML/PHP with external css to MS Word file. I have a php file which is design by external css and i need to convert it in MS word docx file. How to get the proper solution for this problem. I am using PHPWORD script but it's work for basic html and css but not working with external css. If you have any solution, please help me with that.
Thanks
Altab Hossen
I don't think the stuff you can do with css applies to word documents. Sure, word can generate a html file and if you added your css link to that it would work in a browser. But for going the other direction, I think #1 your css would have to be within the document itself and not linked and #2 the contents of your css woul probably be a lot of MSWord custom stuff that works in Word but not in a normal browser.
... ... ... ...
I just opened a .docx file with a plain text editor. It's actually a package containing a dozen other files. One of those files is `styles.xml` and another is `document.xml`
In the actual document there is
Code: Select all
<w:p><w:pPr>
<w:pStyle w:val="Subtitle"/><w:bidi w:val="0"/>
</w:pPr><w:r><w:rPr>
<w:rtl w:val="0"/></w:rPr>
<w:t>Geology 101 Report</w:t>
</w:r></w:p>
And in styles.xml there is
Code: Select all
<w:style w:type="paragraph" w:styleid="Subtitle">
<w:name w:val="Subtitle" /><w:next w:val="Body 2" />
<w:ppr>
<w:keepnext w:val="0" /><w:keeplines w:val="0" /><w:pagebreakbefore w:val="0" /><w:widowcontrol w:val="1" /><w:shd w:val="clear" w:color="auto" w:fill="auto" /><w:suppressautohyphens w:val="0" /><w:bidi w:val="0" /><w:spacing w:before="0" w:after="0" w:line="240" w:linerule="auto" /><w:ind w:left="0" w:right="0" w:firstline="0" /><w:jc w:val="center" /><w:outlinelvl w:val="9" />
</w:ppr>
<w:rpr>
<w:rfonts w:ascii="Baskerville" w:cs="Arial Unicode MS" w:hansi="Baskerville" w:eastasia="Arial Unicode MS" /><w:b w:val="0" /><w:bcs w:val="0" /><w:i w:val="0" /><w:ics w:val="0" /><w:caps w:val="0" /><w:smallcaps w:val="0" /><w:strike w:val="0" /><w:dstrike w:val="0" /><w:outline w:val="0" /><w:color w:val="dc5921" /><w:spacing w:val="6" /><w:kern w:val="0" /><w:position w:val="0" /><w:sz w:val="64" /><w:szcs w:val="64" /><w:u w:val="none" /><w:vertalign w:val="baseline" />
</w:rpr>
</w:style>
This produces the text "Geology 101" in the font Baskerville with the color #dc5921
Maybe this is an XSL stylesheet or XSLT transformation thingamabob?
If using something like
https://github.com/PHPOffice/PHPWord you wouldn't take a pre-existing html document and magically convert it to word. Instead you'd have to write a bunch of php code that describes what you want the output word document to be.