Page 1 of 1

How to replace image in document with external image?

Posted: Thu May 22, 2014 9:03 am
by peterv6i
Hello,
I have a need to replace a image in document with barcode image created with webservice...

I have done in this way:

1.) unziped odt file on disk
2.) saved my barcode.jpg file inside Pictures directory
3.) In content.xml I replaced a "template" image with barcode image (changed path to my barcode image) (and saved content.xml)
4.) ziped all folders...

(Entire process is done on Oracle database with java procedures... we use odt files as template/report engine)

If I run the file I get a dialog that open office noticed something was changed and after that it opens a document without any problem..

What I'am doing wrong? I would like to avoid that dialog showing that file was modified..

Pictures in my folder
Image

Replaced template images with barcode "name" with my barcode image....
Image

This is the final document.. but I would like to avoid warrning dialog that file is "corupted"...
Image

Here is my corrupted file: https://drive.google.com/file/d/0B6Z9wN ... sp=sharing

Re: How to replace image in document with external image?

Posted: Thu May 22, 2014 4:04 pm
by acknak
Open the document (allow the repair), then save into a new file. Compare the first file and the repaired file to see what has changed. That should show what is needed to generate a correct file.

Re: How to replace image in document with external image?

Posted: Fri May 23, 2014 10:03 am
by peterv6i
I have done it.. the difference is almost in every file ?!?

Image

Re: How to replace image in document with external image?

Posted: Fri May 23, 2014 3:14 pm
by acknak
The screen captures don't show all the contents:

Why is the icon for folder "META-INF" a different color?

Have you checked all the contents of the PICTURES folder? At least the image file name is different, although I don't think it matters, OO will change it for you when the document is opened/saved again.

Have you updated the META-INF/manifest.xml file to include the new image file name?

Re: How to replace image in document with external image?

Posted: Fri May 23, 2014 3:36 pm
by peterv6i
acknak wrote: Why is the icon for folder "META-INF" a different color?
because is selected.... ;)

The picture name in "repaired" file is different that in "non repaired" file.


I have also tryed to "unzip" a working copy of document and zip it again with different file name..
Also in this way the file will be corrupted...

Re: How to replace image in document with external image?

Posted: Fri May 23, 2014 4:05 pm
by acknak
This works for me with your "dok.odt" file:

1) Unzip dok.odt in an empty directory:
  • mkdir recovery
    cd recovery
    unzip ../dok.odt
2) Edit META-INF/manifest.xml:
  • add this line:
    <manifest:file-entry manifest:full-path="Pictures/barkoda1.jpg" manifest:media-type=""/>
3) zip the items into a new archive, with the "mimetype" item as the very first in the new archive:
  • Using a command line zip utility, I used this:
    zip -r ../dok_repaired.odt mimetype *

Re: How to replace image in document with external image?

Posted: Mon May 26, 2014 8:09 am
by peterv6i
Hmm..
Still get the error..
Unziped all into folder, modifed manifest.xml, ziped in command prompt and run odt with OO...

Image

Re: How to replace image in document with external image?

Posted: Mon May 26, 2014 2:11 pm
by acknak
Sorry, what you did looks ok to me. I don't see what the problem is.

Here' s the document I get:
 Edit: PS: 
Your zip command output includes something I'm not familiar with:
  • adding: mimetype (172 bytes security) (stored 0%)
I wonder if your zip software is doing/adding something in the archive that causes the problem.

Can you attach the .odt that you get and let us try it?

Re: How to replace image in document with external image?

Posted: Mon May 26, 2014 2:34 pm
by peterv6i
Ok..
here is my ziped file: https://drive.google.com/file/d/0B6Z9wN ... sp=sharing

i'am using: zip 3.0 from (5th julij 2008)
zip.jpg

Re: How to replace image in document with external image?

Posted: Mon May 26, 2014 3:58 pm
by acknak
Sorry, I'm not having any luck finding the difference in your file and mine.

From the zip listing, they're exactly the same except for the order and that your META-INF/manifest.xml has no newline at the end. That shouldn't matter, and adding it in and re-zipping doesn't fix the document.

If I allow OO to repair and then save the result, almost every file is different, so that doesn't help much.

I'm not sure what else to try at this point.

Re: How to replace image in document with external image?

Posted: Mon May 26, 2014 4:17 pm
by RoryOF
Why not link the image? Then you can replace the image file with the new one.

Re: How to replace image in document with external image?

Posted: Mon May 26, 2014 7:00 pm
by acknak
Ok, I see what the difference is now. Somehow the (empty) items in the Configurations2 directory from your last file are present in the document archive as plain files--they should be empty directories.

So, for example, if I unzip my repaired file and list the contents:
  • $ ls -l dok_repaired/Configurations2/
    total 32
    drwxrwxr-x. 2 jes jes 4096 May 23 09:48 accelerator
    drwxrwxr-x. 2 jes jes 4096 May 23 09:54 floater
    drwxrwxr-x. 3 jes jes 4096 May 23 09:48 images
    drwxrwxr-x. 2 jes jes 4096 May 23 09:54 menubar
    drwxrwxr-x. 2 jes jes 4096 May 23 09:54 popupmenu
    drwxrwxr-x. 2 jes jes 4096 May 23 09:54 progressbar
    drwxrwxr-x. 2 jes jes 4096 May 23 09:54 statusbar
    drwxrwxr-x. 2 jes jes 4096 May 23 09:54 toolbar
Note that each item begins with "d" indicating that it is a directory.

If I unzip your document and list the same directory:
  • $ ls -l dok_1/Configurations2/
    total 8
    drwxrwxr-x. 2 jes jes 4096 May 26 04:55 accelerator
    -rw-rw-r--. 1 jes jes 0 May 21 09:23 floater
    drwxrwxr-x. 2 jes jes 4096 May 26 04:55 images
    -rw-rw-r--. 1 jes jes 0 May 21 09:23 menubar
    -rw-rw-r--. 1 jes jes 0 May 21 09:23 popupmenu
    -rw-rw-r--. 1 jes jes 0 May 21 09:23 progressbar
    -rw-rw-r--. 1 jes jes 0 May 21 09:23 statusbar
    -rw-rw-r--. 1 jes jes 0 May 21 09:23 toolbar
You see that only two of the items are directories; the rest are plain empty files (type "-")

If I go through these and remove the files and replace each with a directory of the same name, then re-zip as before, the result opens in AOO with no error.

I can't guess how this may have happened--maybe a difference in the zip software? Although I seem to have the same version (info-ZIP 3.0) as you.

Re: How to replace image in document with external image?

Posted: Tue May 27, 2014 9:50 am
by peterv6i
Ok will try...
thank you!

Re: How to replace image in document with external image?

Posted: Tue May 27, 2014 10:22 am
by RoryOF
There is discussion on the zipping of files in OpenOffice at
http://stackoverflow.com/questions/4957 ... -its-files

This may be of assistance.

Re: How to replace image in document with external image?

Posted: Tue May 27, 2014 10:37 am
by peterv6i
ok will look at this..

The problem is that I must zip a file with Java.. (recursive)..
I will try to do somethink and then I will put source code here if someone will need it...

thank you

Re: How to replace image in document with external image?

Posted: Wed May 28, 2014 3:08 pm
by peterv6i
Is there maybe some java library to insert some external image into odt file (or replace some text with image)? and save the document indo valid odt file?