pdfbox-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tilman Hausherr (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PDFBOX-4583) Drawing only a portion of a PDF (Graphics.clip is ignored/overwritten)
Date Wed, 03 Jul 2019 16:14:00 GMT

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

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

I realize this is more complex than I thought: if I set a clip to 100x100, then do a scale(2,2),
and then ask for the clip size, the result is a 50x50 rectangle. So the reverse transform
should be applied. The next problem is that this won't work properly if there was already
a transform at the beginning. I think one should apply the reverse of the transform "delta"
between the initial transform and "now" (i.e. the time where {{PageDrawer.setClip()}}).

So either I need a way to extract the delta from two transforms, or I need to apply all transforms
not just to graphics but to another transform that follows the graphics device and starts
at identity.

> 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
>          Components: Rendering
>    Affects Versions: 2.0.15
>            Reporter: Jan Buschtöns
>            Assignee: Tilman Hausherr
>            Priority: Major
>             Fix For: 2.0.17, 3.0.0 PDFBox
>
>         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


Mime
View raw message