pdf export draws black rectangles around included png images

Bug #1004887 reported by bpaassen
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Inkscape
Triaged
Medium
Unassigned

Bug Description

I used a SOLARIS "print to file" functionality to make pdf prints of a website I am developing. This website also has png graphics on it. These pdfs are not stuitable for further distribution because they contain timestamps and things like that. Therefore I imported these pdfs into inkscape, removed the unneccessary parts and saved them again in pdf format.

The output pdfs now contain black rectangles around the png graphics. This seems to be an export bug in inkscape. I attached the input pdf and the output pdf in a zip file.

I am using inkscape version 0.48.2 under Windows 7 (64 bit).

Revision history for this message
bpaassen (bpaassen) wrote :
Revision history for this message
su_v (suv-lp) wrote :

Reproduced with Inkscape 0.47, 0.48.x and 0.48+devel r11435 on OS X 10.7.4 (cairo 1.8.8, 1.8.10, 1.10.2 and 1.12.2).

tags: added: exporting pdf
Changed in inkscape:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
su_v (suv-lp) wrote :

Attaching reduced test case (based on the provided original PDF file): the nested structure resulting from the PDF import is flattened step by step, to narrow down the cause. The minimal structure triggering the issue (missing or displaced mask?) looks like this:

1) Mask information (in <defs>):
<mask
       maskUnits="userSpaceOnUse"
       x="0"
       y="0"
       width="1"
       height="1"
       id="mask162"><image
         width="1"
         height="1"
         xlink:href="data:image/png; (…)"
         id="image164" />
</mask>

2) Masked bitmap image (width = height = 1) inside scaled group:
<g
       transform="matrix(8.429732,0,0,8.429732,353.08084,382.57798)"
       id="g4641"><image
         id="image4643"
         mask="url(#mask162)"
         xlink:href="data:image/png; (…)"
         transform="matrix(1,0,0,-1,0,1)"
         height="1"
         width="1" />
</g>

Revision history for this message
su_v (suv-lp) wrote :

Resulting PDF based on the reduced test case (exported with Inkscape 0.48+devel r11435 on OS X 10.7.4, cairo 1.12.2)

tags: added: masking
Revision history for this message
jazzynico (jazzynico) wrote :

Reproduced on Debian testing (cairo 1.12.2) with Inkscape trunk revision 11946.

Changed in inkscape:
status: Confirmed → Triaged
Revision history for this message
Razvan Chisa (ronnyourmatrix) wrote :

I have just encountered this problem. It seems it is related to the PNG graphics.

I have tried to find an alternative solution for properly generating PDF and I have observed some other connections related to this problem:
- it occurs for objects with raster graphics and transparency
- is consistent if the objects are pasted directly into another Inkscape document
- if the object is exported as bitmap, the background appears to be white
- if the object is saved as PNG in another document, there is a gradient affecting the picture (see icons from suv-lp post, the ones from top right)
- if generating PDF, the transparency of the object becomes black color

Some differences when opening an usual transparent PNG:
- if the object is exported as bitmap, the background is transparent
- if saved as PNG, the output is ok (transparent)
- if generating PDF, the output deteriorates the colors (in detail, it looks like it is trying to draw the pixels as vector graphics with gradients because there are multiple colors for the same pixel; zooming changes the colors; the most noticeable difference is when there is white next to a color, making it appear darker)

As I was uploading the pictures, I see that if I open the broken pdf, it is displayed differently in Inkscape than the PDF Viewer (I am using Sumatra PDF Viewer). The same occurs with the document from suv-lp post.

My current solution, starting from the original PDF, is to export objects as bitmap, edit the PNG and make white transparent, paste the picture into the PDF and replace the objects. This is veeeery complicated and I need this problem to be solved so that I can continue my work. Also, some pictures contain white as part of the graphics.

I am using Inkscape 0.48.4 r9939 under Windows 7, 64 bit.

Revision history for this message
drewkeller (drew-drewkeller) wrote :

I ran into this as well, on Inkscape 0.91 r13725 (Windows 7 x64).
I was able to work around it by applying a filter to the PNG image... and then when exporting to PDF, I selected "Rasterize filter effects". This is a little simpler than exporting and editing all of the objects to remove transparency as described above. It's also less permanent, which might be a drawback (you have to remember to do it) or might not (if you want your unmodified objects).

Revision history for this message
matthenry (imatthenryy) wrote :

The black rectangles around the PNG graphics in your exported PDF are likely caused by a bug in Inkscape version 0.48.2. This bug has been fixed in later versions of Inkscape, so I recommend upgrading to the latest version if possible.

In the meantime, there are a few workarounds you can try:

Export your PDF to a different format. For example, you could export to PNG or EPS and then convert that file to PDF using a different program.
Use a different PDF exporter. There are a number of third-party PDF exporters available for Inkscape, such as CairoSVG and Ghostscript.
Manually remove the black rectangles. You can do this using a PDF editor such as Adobe Acrobat or Inkscape itself.
If you choose to manually remove the black rectangles, here are the steps involved:

Open the PDF in Inkscape.
Select the black rectangle around the PNG graphic.
Press the Delete key.
Repeat steps 2 and 3 for all of the black rectangles in your PDF.
Save your PDF.
Here are some additional tips for exporting PDFs from Inkscape:

Make sure that all of your objects are embedded in the PDF. To do this, go to File > Document Properties > Embed Fonts and Images.
Set the PDF version to 1.4 or higher. This will ensure that your PDF is compatible with a wide range of software.
Use a high resolution (e.g. 300 dpi) for best results. by
I hope this helps!https://www.ufabetwins.ai/

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.