Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4744

PageDrawer is not rendering unrotatable Annotations on rotated pages

    XMLWordPrintableJSON

Details

    Description

      Unrotatable Annotations are no longer rendered by the PageDrawer.

      The issue can be reproduced using the attached "simple.pdf" and the following code:

      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();
              }
          }
      

      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?

         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);
         }
      

      The flags of the annotation are:

      Attachments

        1. simple.pdf
          128 kB
          Christian Appl
        2. screenshot-1.png
          31 kB
          Christian Appl

        Activity

          People

            Unassigned Unassigned
            capSVD Christian Appl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: