How to replace image in document with external image?

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

How to replace image in document with external image?

Post 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
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

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

Post 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.
AOO4/LO5 • Linux • Fedora 23
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post by peterv6i »

I have done it.. the difference is almost in every file ?!?

Image
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

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

Post 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?
AOO4/LO5 • Linux • Fedora 23
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post 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...
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

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

Post 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 *
AOO4/LO5 • Linux • Fedora 23
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post by peterv6i »

Hmm..
Still get the error..
Unziped all into folder, modifed manifest.xml, ziped in command prompt and run odt with OO...

Image
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

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

Post 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?
Attachments
dok_repaired.odt
(34.65 KiB) Downloaded 317 times
AOO4/LO5 • Linux • Fedora 23
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post 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
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

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

Post 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.
AOO4/LO5 • Linux • Fedora 23
User avatar
RoryOF
Moderator
Posts: 35210
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post by RoryOF »

Why not link the image? Then you can replace the image file with the new one.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

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

Post 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.
AOO4/LO5 • Linux • Fedora 23
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post by peterv6i »

Ok will try...
thank you!
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
User avatar
RoryOF
Moderator
Posts: 35210
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post 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.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post 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
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
peterv6i
Posts: 10
Joined: Wed May 14, 2014 1:33 pm

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

Post 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?
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
Post Reply