2 Replies Latest reply on Sep 2, 2011 9:05 AM by Kastion2K

    Insert Image Into Word Document

    Kastion2K Level 1

      I have a word document that's a template for printing labels. I'm trying to insert pre-generated labels (JPGS) into the Word document for printing but can't seem to get it right. When I do this:

       

           <cfimage action = "convert" destination = "c:\inetpub\wwwroot\admin\labels\thumbs\#filename#\labelcropped.jpg" source = "#lblImage#" overwrite="true">

           

           <cffile action="read" file="C:\Inetpub\wwwroot\admin\labels\template.doc" variable="docTemplate">

           

           <cfset docTemplate = ReplaceNoCase(docTemplate, "aa", lblImage, "ALL")>

           

           <cffile action="write" output="#docTemplate#" file = "c:\inetpub\wwwroot\admin\labels\thumbs\#filename#\#filename#.doc">

       

      The word document ends up corrupt and can't be opened by Word. How can I insert images into a word document? I have "aa" placeholders that I want to replace with the images in question.

        • 1. Re: Insert Image Into Word Document
          Owain North Level 4

          Wow, that's some of the more optimistic code I've seen in a while.

           

          A Word document is a binary file, you cannot simply insert text into the middle of a binary file and expect it to work, that's not how they work unfortunately. You might be able to read an RTF file in, but I don't think they support images.

           

          Could you use a plain text file as the source and a PDF as the output? That'd be easy. Or even just use CFDocument to create a PDF with the images, then print that. Does it actually need to be Word?

          1 person found this helpful
          • 2. Re: Insert Image Into Word Document
            Kastion2K Level 1

            It could be PDF but the reasons I'm using word is:

             

            1) Downloaded template from here http://www.worldlabel.com/Pages/wl-ol125.htm#templates

            2) Word automatically resized my labels to fit in the slot in the template

             

            If there's a way I can use the PDF template and resize my labels (and write/append the labels to X/Y positions) then I would consider attempting this with a PDF