Author: tilman
Date: Thu Feb 6 09:56:10 2025
New Revision: 1923609
URL: http://svn.apache.org/viewvc?rev=1923609&view=rev
Log:
PDFBOX-4744: reconstruct NoRotate annotations that have transparencies
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1923609&r1=1923608&r2=1923609&view=diff
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
(original)
+++
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Thu Feb 6 09:56:10 2025
@@ -1659,6 +1659,16 @@ public class PageDrawer extends PDFGraph
if (annotation.isNoRotate() && getCurrentPage().getRotation() != 0)
{
+ appearance = annotation.getAppearance();
+ if (appearance != null && appearance.getNormalAppearance() != null
&&
+ appearance.getNormalAppearance().isStream() &&
+
hasTransparency(appearance.getNormalAppearance().getAppearanceStream()))
+ {
+ // PDFBOX-4744: avoid appearances with transparency groups
until we have fixed
+ // the rendering. A real solution should probably be
+ // in PDFStreamEngine.processAnnotation().
+ annotation.constructAppearances();
+ }
PDRectangle rect = annotation.getRectangle();
AffineTransform savedTransform = graphics.getTransform();
// "The upper-left corner of the annotation remains at the same
point in
@@ -1667,6 +1677,7 @@ public class PageDrawer extends PDFGraph
rect.getLowerLeftX(), rect.getUpperRightY());
super.showAnnotation(annotation);
graphics.setTransform(savedTransform);
+ annotation.setAppearance(appearance); // restore
}
else
{
@@ -1674,6 +1685,32 @@ public class PageDrawer extends PDFGraph
}
}
+ private boolean hasTransparency(PDFormXObject form) throws IOException
+ {
+ if (form == null)
+ {
+ return false;
+ }
+ PDResources resources = form.getResources();
+ if (resources == null)
+ {
+ return false;
+ }
+ for (COSName name : resources.getXObjectNames())
+ {
+ PDXObject xObject = resources.getXObject(name);
+ if (xObject instanceof PDTransparencyGroup)
+ {
+ return true;
+ }
+ if (xObject instanceof PDFormXObject &&
hasTransparency((PDFormXObject) xObject))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* {@inheritDoc}
*/