hefronmedia / pdfsizeopt

Automatically exported from code.google.com/p/pdfsizeopt
0 stars 0 forks source link

Missing images #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Images sometimes do not show in the pdfsizeopt output.
I have an example file (that I unfortunately can not post) that was made by
OpenOffice.org 3.1.  The image in the original has a soft mask, and the
mask is solid black and has an inverted /Decode entry of [ 1 0 ].
pdfsizeopt drops the /Decode entry, which changes the mask from passing
every pixel of the image to dropping every pixel of the image, and the PDF
ends up with a white hole where the image should be.  The patch below keeps
UpdatePdfObj() from clearing the /Decode entry.
William
williambader@hotmail.com

--- pdfsizeopt/pdfsizeopt.py-   2010-03-24 21:06:15.000000000 +0000
+++ pdfsizeopt/pdfsizeopt.py    2010-05-09 03:52:06.000000000 +0100
@@ -2592,15 +2592,17 @@
     else:
       pdf_obj.Set('BitsPerComponent', pdf_image_data['BitsPerComponent'])
       pdf_obj.Set('ColorSpace', pdf_image_data['ColorSpace'])
-      pdf_obj.Set('Decode', pdf_image_data.get('Decode'))
+      if pdf_obj.Get('Decode') == None:
+        # Update Decode only if it is currently not set
+        pdf_obj.Set('Decode', pdf_image_data.get('Decode'))
     pdf_obj.Set('Filter', pdf_image_data['Filter'])
     pdf_obj.Set('DecodeParms', pdf_image_data.get('DecodeParms'))
     pdf_obj.Set('Length', len(pdf_image_data['.stream']))
-    # Don't pdf_obj.Set('Decode', ...): it is goot as is.
+    # Don't pdf_obj.Set('Decode', ...): it is good as is.
     pdf_obj.stream = pdf_image_data['.stream']

   def CompressToZipPng(self):
-    """Compress self.idat to self.compresson = 'zip-png'."""
+    """Compress self.idat to self.compression = 'zip-png'."""  
     assert self
     if self.compression == 'zip-png':
       # For testing: ./pdfsizeopt.py --use-jbig2=false --use-pngout=false
pts2ep.pdf

PDF objects for the image in the original file:
13 0 obj
<</Type/XObject/Subtype/Image/Width 1011 /Height 626 /BitsPerComponent 8
/Length 14 0 R
/Filter/FlateDecode/ColorSpace/DeviceRGB
/SMask 15 0 R
>>
stream
endstream
endobj
14 0 obj
24398
endobj
15 0 obj
<</Type/XObject/Subtype/Image/Width 1011 /Height 626 /BitsPerComponent 8
/Length 16 0 R
/Filter/FlateDecode/ColorSpace/DeviceGray
/Decode [ 1 0 ]
>>

PDF objects for the image in the unpatched pdfsizeopt output:
49 0 obj
<</BitsPerComponent 8/ColorSpace/DeviceRGB/Filter/FlateDecode/Height
626/Length 20524/SMask 50 0 R/Subtype/Image/Type/XObject/Width 1011>>stream
endstream endobj
50 0 obj
<</BitsPerComponent 1/ColorSpace/DeviceGray/Filter/FlateDecode/Height
626/Length 100/Subtype/Image/Type/XObject/Width 1011>>stream
endstream endobj

Original issue reported on code.google.com by william.bader@gmail.com on 9 May 2010 at 5:06

Attachments:

GoogleCodeExporter commented 9 years ago
I have similar problem, but my PDF file is created by XeLaTeX. I tried to use 
the patch but it doesn't work for me. Problem remains the same.

I attach file where is image and after running the pdfsizeopt.py, the PDF 
viewer is unable to display this image.

The composition of PDF is very similar to what william.bader described above in 
this issue.

Original comment by hata.ra...@gmail.com on 12 Jul 2010 at 2:35

Attachments:

GoogleCodeExporter commented 9 years ago
I forgot add PDF file after running pdfsizeopt.py. Now I attach it as well.

Original comment by hata.ra...@gmail.com on 13 Jul 2010 at 10:44

Attachments:

GoogleCodeExporter commented 9 years ago
@hata.radim: Your problem has been fixed in r150 (it converts 2.pdf correctly). 
If the fix doesn't work for you, please create a new issue for that.

Original comment by pts...@gmail.com on 10 Feb 2011 at 11:45

GoogleCodeExporter commented 9 years ago
Closing this issue now. Feel free to reopen it if you have an example PDF with 
an image pdfsizeopt doesn't optimize properly.

Original comment by pts...@gmail.com on 4 Mar 2011 at 1:41