pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Drawing only a portion of a PDF (Graphics.clip is ignored/overwritten)
Date Wed, 26 Jun 2019 16:16:39 GMT
Very good question. Yes, PageDrawer uses setClip(). We can still do 
this, but should remember the initial clipping path and intersect that 
one. Please create an issue tomorrow if there isn't a different opinion.

Tilman

Am 26.06.2019 um 09:29 schrieb Jan Buschtoens:
> Hi.
>
>
> I want to use PDFBox to draw PDFs in a swing application.
>
>
> I already created a  new issue for a problem I had on Linux (PDFBOX-4581). But unrelated
to that I had another problem (on windows and  linux), and I wanted to ask first if I'm doing
something wrong before I create a new issue.
>
>
> 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
wohle PDF is drawn. I believe that 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, wheras the former resets the current clip.
>
>
>
> My code is essentially the following:
>
>
>          @Override
>          public void paint(final Graphics g) {
>
>              final Graphics2D g2 = (Graphics2D) g;
>              try {
>                  PDDocument pdDocument = PDDocument.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);
>              }
>          }
>
>
> --
>
> { Geschaeftsfuehrer: Dipl.-Inform. Christopher Asp,  Amtsgericht: Mannheim,  HRB: 105845
}



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


Mime
View raw message