Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Include Inline Image in HTML

by Anonymous Monk
on Jan 03, 2011 at 21:44 UTC ( #880263=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Monks:

Thanks for providing this site. Great information here, always!

Would someone know if it is possible to include the binary data for a jpeg directly in HTML (create an inline image). Here is why I ask:

We have an in-house created Perl application on a Linux server that creates a MS Word doc simply by send HTML to the browser and setting the MIME type of the page to "application/msword". Everyone in the company uses IE and has MS Word installed on their workstation, so doing this has not been a problem. When the HTML is sent to the browser, a prompt displays to the user to download the Word doc.

The HTML contains image tags. The source for each image is a cgi page that retrieves the binary data for the image from a database and prints it to output as MIME type "image/jpeg". The image tags look something like this then:

<img src="https://subdomain.ourserver.com/showimage.cgi/00000000000.jpg" />

This worked great for all versions of Word until Word 2007. The Word doc still generates just fine. However, images within the doc do not display. We have determined that this may be due to a GPO that blocks anything that Word considers to be external content. Even though the URL to the image resides within the company intranet, Word security seems to still block it. We cannot get a change to this GPO. We also cannot seem to modify Word settings to trust the URL for the image. Googling shows that many people are experiencing this issue with Word 2007 and there does not seem to be a solution aside from embedding the image in Word after the document has been created.

Embedding the image after the fact would be inconvenient for the users to do, so we are trying to find a way to force Word to see the image as embedded at the time the document is created. We thought that if we could add the binary data for the image somehow directly to the page that generates the HTML, that might resolve the issue. But we are stuck trying to figure out how to send two different MIME types - the one for the main document and then the one for each image that is written to the document. None of us are well versed in Perl and so don't know how it can be done, if at all. Also, we need to be able to do it in a loop as more than one record with binary image data will need to be written to the doc.

Thanks in advance for any information you are able to provide. Please let me know if you need more info from me.

Comment on Include Inline Image in HTML
Re: Include Inline Image in HTML
by Anonyrnous Monk (Hermit) on Jan 03, 2011 at 22:14 UTC

    For the general idea of how to embed image content in HTML, see Inline Images with Data URLs.  I have no idea if any of this works with MS Word, though...

    (Also, there are typically size limitations, even if the feature is supported by the rendering application.)

Re: Include Inline Image in HTML
by unlinker (Monk) on Jan 04, 2011 at 04:23 UTC

    If the Data URL method of embedding images continues to be blocked, do consider generating and streaming an MS-Word Document with Win32::OLE rather that stream an HTML file.

      "We have an in-house created Perl application on a Linux server"
      --
      A math joke: r = | |csc(θ)|+|sec(θ)|-||csc(θ)|-|sec(θ)|| |
      Online Fortune Cookie Search
        Ooops! Sorry, should have read carefully :)
Re: Include Inline Image in HTML
by marto (Chancellor) on Jan 04, 2011 at 11:42 UTC

    Don't you actually want to create a Microsoft Word document? If so you could try to use OpenOffice::UNO to create a document, save it as word format and deliver it to the user in the normal fashion.

      That's a good idea. The ultimate goal is to create a Word doc that has embedded images. I will investigate OpenOffice::UNO and reply back to all on whether or not it worked. Thanks to everyone who has replied so far!
      A. Kilgore

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://880263]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-09-17 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (97 votes), past polls