#148 Images in document templates are not preserved

closed-fixed
ODT Writer (14)
5
2010-10-27
2010-10-18
pachiburke
No

Steps to reproduce the bug:
1. Create an odt template (my-template.odt) with an image in its header
2. Use the template to generate an ODT document with the --stylesheet=my-template.odt
3. Open the generated document

The images in the header are not preserved. It's probably due to the Pictures subdir not being copied, and it may contain elements that are not part of contents.xml (such as headers and footers).

Discussion

  • Dave Kuhlman

    Dave Kuhlman - 2010-10-20

    I don't understand why we would expect images to be copied from the stylesheet into the target document. odf-odt writer supports the use of an odt document as container for *styles*.

    Why should images be copied? What is the use or need for doing this?

    - Dave

     
  • pachiburke

    pachiburke - 2010-10-20

    I see. I expected that, when a full odt file was provided as a template, the conversion would only replace contents.xml.

    My usecase is in fact very simple. I was trying to use as a template an odt file with a header with an image logo in it.

    I thought I could use raw::odt, but that affects, AFAICT, contents.xml, and headers are stored and defined in styles.xml so that doesn't work. The only really missing information is the picture files (stored in /Pictures) which correspond to the header images.

     
  • Dave Kuhlman

    Dave Kuhlman - 2010-10-20

    And, the usecase suggested by Matt, over on the docutils-users list is:

    "I could see this being used as a watermark, or any company template
    that has a logo in it...."

    Both of those seem worth addressing. So, give me a little time to look into it.

    Stylesheets (and styles.odt) for odf-odt writer were not originally intended for this. (How could they be when I didn't understand that need.) But, maybe it can be made to fit in smoothly.

    Give me a few days to look into it.

    And thanks much for the suggestion and guidance.

    - Dave

     
  • pachiburke

    pachiburke - 2010-10-21

    Thank you very much, Dave!

     
  • Dave Kuhlman

    Dave Kuhlman - 2010-10-25

    I've added code to the odf-odt writer so that it copies images from the Pictures directory in the stylesheet (styles.odt) into the target .odt document. I've checked that change into the SVN repository.

    pachiburke, could you please try it and let me know if this fix does what you expected. Thanks.

    - Dave

     
  • pachiburke

    pachiburke - 2010-10-26

    It works like a charm and images show fine. Though, I had to change __init__.py in two places as ZipFile.writestr() has just grown the additional compress_type parameter in Python 2.7 and I'm using 2.6 here.

    So,

    zfile = zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED) -> zfile = zipfile.ZipFile(f, 'w')

    outzipfile.writestr(name, imageobj, zipfile.ZIP_STORED) -> outzipfile.writestr(name, imageobj)

    Apparently, all works fine with that change.

    Thanks.

    - Pachi

     
  • Dave Kuhlman

    Dave Kuhlman - 2010-10-26

    I've removed the compression argument from the calls to write and writestr. I left the compression argument on the call to the constructor. We need to specify that we want to create a compressed file. I checked the docs for Python 2.5 and 2.6, and both of those support the compression argument on the constructor.

    I've checked this fix into the SVN repository.

    Pachi, when you try it, please let me know if this works for you.

     
  • pachiburke

    pachiburke - 2010-10-27

    Yes, those are the two lines I changed here and it works fine. My comment about the change in the constructor signature is wrong (I should have checked, as only the writestr changes were needed here.

    Thank you!

     
  • pachiburke

    pachiburke - 2010-10-27
    • status: open --> closed-fixed
     

Log in to post a comment.