Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Insert Image Into Word Document

New Here ,
Sep 02, 2011 Sep 02, 2011

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.

TOPICS
Advanced techniques
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 02, 2011 Sep 02, 2011

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2011 Sep 02, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources