Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:01:51+00:00 2026-06-04T04:01:51+00:00

I took over the development of an application which enables users to download some

  • 0

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 !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:01:53+00:00Added an answer on June 4, 2026 at 4:01 am

    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:

    • OpenTbs convert html tags to MS Word tags
    • How can I convert a docx document to html using php?

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

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

    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:

    #!/bin/php -n
    <?php
        $opts = array('file'=>array('header'=>'Content-type: application/vnd.ms-word'."\r\n".'Content-type: application/vnd.ms-word'."\r\n"));
        $resource = stream_context_create($opts);
        $doc = fopen('asDoc.doc','w+',false,$resource);
        if (!$doc)
        {
            die('FFS');
        }
        $html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
        $html .='<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\"><title>Foo</title></head><body><h1>Hello, world</h1></body></html>';
        fwrite($doc,$html);
        fclose($doc);
        exit();
    ?>
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I took over some old php application with MySQL as database. Inside the database,
Some weeks ago at work I took over a Java-based back-end web application written
I took over an old HTML based site with all hard coded links, no
I recently took over management of a Windows 2003 server. The application log is
Recently I encountered a bug in an application I took over from another developer.
Some time ago we took over the responsibility of a legacy code base. One
I recently took over development of a mobile website that uses the Facebook Graph
I recently took over some C and firmware responsibilities at work, and am having
I recently took over some work form another developer and am trying to understand
I just took over development of an existing EE website and am new to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.