Search code examples
phpckeditordoc

creating docx file from html code typed in ckeditor


I want to create docx file of the content typed in ckeditor, I tried many solutions like vsword, phpword. The problem with this solution is I need to go node by node to insert some line of html code, Is their any possible way to hold all html content in single variable and parse it directly to insert the content in docx file, or please suggest some good option to create docx file from html, Html may contain some style like color, font or Images. the more I read, google, more it is getting complicated for me, Need help


Solution

  • I finally came up with adjusted solution for above problem,

    step 1)configure ck editor so that it will give you content in html tags(in my case there was plugin which was causing disturbing the html tags, I simply removed it)

    step 2) bring all the content in one variable where you need to download the file(I created file when downloading)

    step 3)

    header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment; filename=$filename1");
    echo "<html>";
    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
    echo "<body>";
    echo $artc;
    echo "</body>";
    echo "</html>";
    

    this will create the file add html content and force browser to download the file

    (Note: this is not actually the doc file,we are forcing browser to download the file, I was in need a quick working solution )