I took over the development of an application which enables users to download some reports.
The system set up is as follows :
- Create a *.html file with data retrieved by php.
- Copy all the content of the *.html file in a *.doc file (not a real *.doc file, just a *.html file with the extension “.doc”).
- The *.doc is available in download.
I know that is a weird solution to create report files, and I had a lot of difficulties to set up the CSS to work great in the *.doc file.
For example, now I need to set up margins at 0cm, but of course, when I open the generated *.doc in a text-editor like OpenOffice, LibreOffice, MSWord, he’s open in WEB mode CSS margins sets to 0cm works fine. But, the users needs to open the file in STANDARD mode (like a real *.doc file) and the don’t want to make some actions to convert the document, or sets margins to 0 cm (…).
So, I’ve found the solution to convert the *.html OR *.doc file in *.odt, unzip the *.odt file, modify the file “styles.xml” which allows me to sets the “STANDARD” margins to 0cm, then, re-save as *.doc format.
This solution works great, BUT, I’ve only achieve thi on my PC with the LibreOffice GUI.
When I try to convert the *.html or *.doc file in *.odt with any programm in command-line (even the LibreOffice convert module), the *.odt file is not the same as when I use the LibreOffice GUI. So I’ve try with other convertion script like :
- pandoc
- abiword
- ooconvert
So, is there a way to convert properly my *.html fil into *.odt file ?
Or another way which allows me to do what I want ?
Thanks.
EDIT/SOLVED :
Works with JODConverter !!
If you want to preserve the HTML, I’d still maintain LiveDocx might just prove useful. I did some more digging, and stumbled on phpdocx. On the bottom of the page there’s a link that shows you how to embed HTML.
Both LiveDocX and phpdocx offer examples on their respective sites. I suggest you browse through those.
SO showed up a few times, too: interesting questions might be:
I know the latter is the opposite of what you’re trying to do, but don’t write it off just for that reason. Often, it’s quite helpful to look at things from another perspective.
Since your last comment leads me to believe you haven’t actually gotten round to coding (
I just need a script etc...) I would like to say that SO is not a code generator. When you’re done reading about phpdocx and livedocx, perhaps you should read what makes a good question.I found what you were looking for, I think, here. If you want to use the php-cli, my guess would be setting your script’s output stream to a file, and using the headers found below (copy-paste from link).
Sorry if I came across a bit harsh, with the remark on SO not being a code generator, and the link to ‘what makes a good question’. Didn’t mean to bash you.
UPDATE
Sorry, the previous example would only work as a download link: below a working script that turns out a .doc file, based on a html string:
The headers are defined in the context stream, so the first two lines of code are crucial. As is the
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">meta tag. All else is pretty basic.All functions you need are here, so refer to their man pages for more info if you want to know what does what…
Best of luck