How to download a website as ms word with the pictures inside

Started by
2 comments, last by aregee 9 years, 9 months ago

So I have a form in php that has some pics in it. when the user submits, it takes them to a confirmation page which is also php, in this confirmation page I have a button that downloads the page as ms word, when I open the document the pictures are not visible because they are not in the same directory, could there be a way to download everything at the same time or something or idk have the picture be a part of the website without using image src , the code is quite long ,I attached both files so you can see,

Advertisement

I have entirely no experience with generating Word documents, so I'm just guessing, but have you tried using a data URI instead of a URL to the file for the images?

You should probably be aware that a html document that you give a .doc extension is still a html document, not a word document and thus it can't include images (it can link to images but those images will have to be downloaded separatly) (Other office suites might also have trouble opening those files as they won't be in the expected format)

A far better solution is to actually generate a word document using for example: http://phpword.codeplex.com/ (It is very easy to use)

If you absolutely insist on using renamed html documents you will have to make an archive (zip for example) containing all the required files (images, stylesheets, etc) or to use data uris (<img src="data::image/png;base64,{base64encodedimagedata}"/>) but i don't know if word supports those. (it might work in newer versions of word (Microsoft added partial support for it in IE8 and made it semi decent in IE9)

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

I worked on something in the past, I think it was called "Microsoft Office SDK" or "Word SDK" or something like that, that I used to generate Word documents on the fly (programmatically). I tried to find it again for another question here recently with a similar question, but I couldn't find any references to that any more. Maybe it is included in the "Platform SDK" now, like you do with "Direct X"? Unless Microsoft has discontinued that SDK, there should exist something to generate Word documents 'on the fly'.

Other than that, I remember copying and pasting a whole webpage into Word, would give a good representation of the web page as a word document.

Same goes if you are opening HTML documents in Word. Just remember to save the document as a Word document, and not HTML.

This topic is closed to new replies.

Advertisement