[ 
https://issues.apache.org/jira/browse/PDFBOX-4094?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16360619#comment-16360619
 ] 

Maruan Sahyoun commented on PDFBOX-4094:
----------------------------------------

[~mveron] PDFBox doesn't always generate the appearance for annotations if 
there is none. But if the appearance is available it can render things like 
stamps. There are some issues with transparency groups and other areas like 
blend modes though but in general it does a good job for most applications.

Back to the rendering of annotations. I do understand why you don't want to 
include them in the rendering. The drawback I wanted to point you to - similar 
to what [~tilman] pointed out - is that some of the content one would typically 
like to see printed is also an annotation. So disabling the rendering of *all* 
annotation types is probably not the way to go. There needs to be a way to only 
disable specific annotations from rendering, which might also include disabling 
all annotations.

> Add support for a flag disabling the rendering of PDF annotations in 
> PDFRenderer
> --------------------------------------------------------------------------------
>
>                 Key: PDFBOX-4094
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4094
>             Project: PDFBox
>          Issue Type: Wish
>          Components: Rendering
>    Affects Versions: 2.0.8
>            Reporter: Maxime Veron
>            Priority: Minor
>
> Regardless if annotations are supposed to be printed or not on the PDF, would 
> it not be interesting to possess a flag allowing to choose if annotations 
> should be printed on top of the document pages?
>  
> Here is a diff of a very rough implementation of it : 
>  
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java 
> b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
> --- a/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
> +++ b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
> @@ -35,6 +35,9 @@ public class PDFRenderer
>      protected final PDDocument document;
>      // TODO keep rendering state such as caches here
>  
> +    // parameter used to know if the rendering should include annotations 
> +    private boolean renderAnnotations = true;
> +
>      /**
>       * Creates a new PDFRenderer.
>       * @param document the document to render
> @@ -224,4 +227,14 @@ public class PDFRenderer
>      {
>          return new PageDrawer(parameters);
>      }
> +
> +    public void setRenderAnnotations(boolean render) 
> +    {
> +        this.renderAnnotations = render;
> +    }
> +
> +    public boolean renderAnnotations() 
> +    {
> +        return renderAnnotations;
> +    }
>  }
> diff --git a/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java 
> b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
> --- a/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
> +++ b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
> @@ -195,11 +195,13 @@ public class PageDrawer extends PDFGraphicsStreamEngine
>  
>          processPage(getPage());
>  
> -        for (PDAnnotation annotation : getPage().getAnnotations())
> -        {
> -            showAnnotation(annotation);
> +        if (getRenderer().renderAnnotations()) 
> +        { 
> +            for (PDAnnotation annotation : getPage().getAnnotations())
> +            {
> +                showAnnotation(annotation);
> +            }
>          }
> -
>          graphics = null;
>      }
>  
> {code}
> And an exemple of a use case: 
> {code:java}
> PDDocument doc = getPDDocument(); 
> PDFRenderer pdfRenderer = new PDFRenderer(doc);
> pdfRenderer.setRenderAnnotations(false);
> pdfRenderer.renderImage(page);
>  
> {code}
> By default, this would be keeping the same behavior as it used to (aka : 
> print the annotations) but possess an opt-out feature.
>  
> Best regards,
> M.Veron



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to