[ https://issues.apache.org/jira/browse/PDFBOX-4744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17915957#comment-17915957 ]
Tilman Hausherr edited comment on PDFBOX-4744 at 1/22/25 8:40 AM: ------------------------------------------------------------------ I've tried solving this one a few times over the years and failed. Yesterday while playing around and trying all sort of modifications, I added {{graphics.translate(-30, 0);}} just before {{super.showAnnotation(annotation);}} and the annotation appeared, but in the "wrong" rotation, despite that we did apply a rotation transformation to the graphics device. This pointed me to transparency groups, where we render into a BufferedImage. So at this time there are two workarounds that make this work but are unsatisfying: 1) ignoring the /Group attribute everywhere 2) recreate the /AP ourself before rendering. I suspect that a real solution would be to apply another rotation somewhere in {{{}PDFStreamEngine.processAnnotation(){}}}, but that method is very dangerous to change and we have only 3 test cases. was (Author: tilman): I've tried solving this one a few times over the years and failed. Yesterday while playing around and trying all sort of modifications, I added {{graphics.translate(-30, 0);}} just before {{super.showAnnotation(annotation);}} and the annotation appeared, but in the "wrong" rotation, despite that we did apply a rotation transformation to the graphics device. This pointed me to transparency groups, where we render into a BufferedImage. So at this time there are two workarounds that make this work but are unsatisfying: 1) ignoring the /Group attribute everywhere 2) recreate the /AP ourself before rendering. > PageDrawer is not rendering unrotatable Annotations on rotated pages > -------------------------------------------------------------------- > > Key: PDFBOX-4744 > URL: https://issues.apache.org/jira/browse/PDFBOX-4744 > Project: PDFBox > Issue Type: Bug > Components: Rendering > Affects Versions: 2.0.18 > Reporter: Christian Appl > Priority: Major > Labels: Annotations, PDFBox, PageDrawer > Attachments: screenshot-1.png, simple.pdf > > > Unrotatable Annotations are no longer rendered by the PageDrawer. > The issue can be reproduced using the attached "simple.pdf" and the following > code: > {code:java} > public static void main(String... args) { > File pdfFile = new File("pathto", "simple.pdf"); > BufferedImage actualImage = null; > try { > try (PDDocument document = PDDocument.load(pdfFile)) { > PDFRenderer pdfRenderer = new PDFRenderer(document); > pdfRenderer.setAnnotationsFilter(PDAnnotation::isPrinted); > pdfRenderer.setDefaultDestination(RenderDestination.VIEW); > actualImage = pdfRenderer.renderImage(0); > } > if (actualImage != null) { > ImageIO.write(actualImage, "png", new File("somePath", > "out.png")); > } > } catch (IOException e) { > e.printStackTrace(); > } > } > {code} > When setting the page rotation to 0 the annotation can be seen in the > "out.png", when selecting another rotation, it is gone. > I am assuming, that the following code in PageDrawer (Method: > showAnnotation(PDAnnotation annotation) Lines: 886 to 892) is not working as > expected. Maybe the rotation anchor should be set to a different position? > {code:java} > if (annotation.isNoRotate() && this.getCurrentPage().getRotation() != 0) { > PDRectangle rect = annotation.getRectangle(); > AffineTransform savedTransform =this.graphics.getTransform(); > > this.graphics.rotate(Math.toRadians((double)this.getCurrentPage().getRotation()), > (double)rect.getLowerLeftX(),(double)rect.getUpperRightY()); > super.showAnnotation(annotation); > this.graphics.setTransform(savedTransform); > } else { > super.showAnnotation(annotation); > } > {code} > The flags of the annotation are: > !screenshot-1.png! -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org