You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2019/06/27 18:15:00 UTC

[jira] [Commented] (PDFBOX-4583) Drawing only a portion of a PDF (Graphics.clip is ignored/overwritten)

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

Tilman Hausherr commented on PDFBOX-4583:
-----------------------------------------

It turns out that it is more tricky than I thought. Just applying the clip isn't enough, because the current transform changes all the time. So the initial clip has to be transformed as well. And the initial clip has to be saved / restored when we temporarily replace the graphics object (for transparencies or patterns). I'll try to do that this WE.

> Drawing only a portion of a PDF (Graphics.clip is ignored/overwritten)
> ----------------------------------------------------------------------
>
>                 Key: PDFBOX-4583
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4583
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Jan Buschtöns
>            Priority: Major
>         Attachments: clip_PDFBox_FORMGEN-2184-master.zip
>
>
> I want to use PDFBox to draw PDFs in a swing application.
> I want to draw only a portion of the PDF. As far as I know, the way to do this in swing is with the "clip"-method on the Graphics object. However, no matter what clip I set, the whole PDF is drawn.
> PDFRenderer calls "setClip", when it probably should use "clip". The latter sets the current clip to the intersection of the old current clip and the provided shape, whereas the former resets the current clip
> I've attached an example maven project, but the gist is:
> {code:java}
>           @Override 
>           public void paint(final Graphics g) { 
>  
>               final Graphics2D g2 = (Graphics2D) g; 
>               try { 
>                   PDDocument pdDocument = DDocument.load(App.class.getResourceAsStream("somepdf.pdf")); 
>                   g2.clip(new Rectangle(20, 20)); 
>                   final PDFRenderer pdfRenderer = new org.apache.pdfbox.rendering.PDFRenderer(pdDocument); 
>                   pdfRenderer.renderPageToGraphics(0, g2); 
>               } catch (final IOException e) { 
>                   throw new RuntimeException(e); 
>               } 
>           }
>   {code}



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

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