Preserve transparency when converting to image with rgba
--------------------------------------------------------
Key: PDFBOX-738
URL: https://issues.apache.org/jira/browse/PDFBOX-738
Project: PDFBox
Issue Type: Bug
Components: PDModel
Affects Versions: 1.2.0
Environment: all
Reporter: Armando Singer
Priority: Minor
When converting a pdf page to an image, the transparency is lost because
PDPage.drawImage() sets the background color to white: graphics.setBackground(
Color.WHITE );
The desired behavior is to preserve transparency when rgba color is set, and to
fall back to white when rgb is used.
The following change works with either color mode:
+
+ /**
+ * Fully transparent that can fall back to white when image type has no
alpha.
+ */
+ private static final Color TRANSPARENT_WHITE = new Color( 255, 255, 255, 0
);
+
private COSDictionary page;
/**
@@ -706,7 +711,7 @@
BufferedImage retval = new BufferedImage( widthPx, heightPx, imageType
);
Graphics2D graphics = (Graphics2D)retval.getGraphics();
- graphics.setBackground( Color.WHITE );
+ graphics.setBackground( TRANSPARENT_WHITE );
Attached is a patch and some sample pdfs and images.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.