Skip to content

Commit a7d0acf

Browse files
committed
PDFBOX-4744: reconstruct NoRotate annotations that have transparencies
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1923610 13f79535-47bb-0310-9956-ffa450edef68
1 parent eeff95f commit a7d0acf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,16 @@ public void showAnnotation(PDAnnotation annotation) throws IOException
15801580
}
15811581
if (annotation.isNoRotate() && getCurrentPage().getRotation() != 0)
15821582
{
1583+
appearance = annotation.getAppearance();
1584+
if (appearance != null && appearance.getNormalAppearance() != null &&
1585+
appearance.getNormalAppearance().isStream() &&
1586+
hasTransparency(appearance.getNormalAppearance().getAppearanceStream()))
1587+
{
1588+
// PDFBOX-4744: avoid appearances with transparency groups until we have fixed
1589+
// the rendering. A real solution should probably be
1590+
// in PDFStreamEngine.processAnnotation().
1591+
annotation.constructAppearances();
1592+
}
15831593
PDRectangle rect = annotation.getRectangle();
15841594
AffineTransform savedTransform = graphics.getTransform();
15851595
// "The upper-left corner of the annotation remains at the same point in
@@ -1588,13 +1598,40 @@ public void showAnnotation(PDAnnotation annotation) throws IOException
15881598
rect.getLowerLeftX(), rect.getUpperRightY());
15891599
super.showAnnotation(annotation);
15901600
graphics.setTransform(savedTransform);
1601+
annotation.setAppearance(appearance); // restore
15911602
}
15921603
else
15931604
{
15941605
super.showAnnotation(annotation);
15951606
}
15961607
}
15971608

1609+
private boolean hasTransparency(PDFormXObject form) throws IOException
1610+
{
1611+
if (form == null)
1612+
{
1613+
return false;
1614+
}
1615+
PDResources resources = form.getResources();
1616+
if (resources == null)
1617+
{
1618+
return false;
1619+
}
1620+
for (COSName name : resources.getXObjectNames())
1621+
{
1622+
PDXObject xObject = resources.getXObject(name);
1623+
if (xObject instanceof PDTransparencyGroup)
1624+
{
1625+
return true;
1626+
}
1627+
if (xObject instanceof PDFormXObject && hasTransparency((PDFormXObject) xObject))
1628+
{
1629+
return true;
1630+
}
1631+
}
1632+
return false;
1633+
}
1634+
15981635
/**
15991636
* {@inheritDoc}
16001637
*/

0 commit comments

Comments
 (0)