Description
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.