Gérard KESTER wrote:
Auriez vous oublié de décaler la deuxième
page, par hasard ?
I had no idea why you needed that offset, so I removed it.
I just wanted to make my point:
1 page = 1 Graphics2D instance.
DO NOT REUSE THE SAME g2d FOR EVERY PAGE!
Create a new instance.
Pour les autres propositions
Have a look at the following three examples:
http://1t3xt.info/examples/browse/?page=toc&id=369
The way I see it, you want to create a genealogical tree that
spans multiple pages, but you are making it very difficult for
yourself. (Why???)
Suppose we have to draw a rectangle and a circle on a canvas
that measures 200 x 200 pts. However, our page size is only
100 x 100 pts. How are we going to achieve this?
I've mixed two solutions in this example:
http://1t3xt.info/examples/browse/?page=example&id=367
For the rectangle, I used the 'difficult way' (I think that's
the way you are trying to do it).
For the circle, I used the 'proper way' (which is incidentally
the easiest way).
Let's split the example in two. The following example draw the
rectangle: http://1t3xt.info/examples/browse/?page=example&id=368
As you can see I create a new Graphics2D instance for every page:
g2d = directContent.createGraphicsShapes(100, 100);
Note that for reasons of simplicity, I didn't use AffineTransform,
I just calculated the new offsets (you're free to adapt the
example if necessary). Point is that you have to RECREATE THE
GRAPHICS STATE for every page. Personally, I don't like this approach.
I'd never do it this way. I'd do it like this:
http://1t3xt.info/examples/browse/?page=example&id=369
I create a PdfTemplate with the size of the complete canvas:
PdfContentByte directContent = writer.getDirectContentUnder();
PdfTemplate canvas = directContent.createTemplate(200, 200);
Graphics2D g2d = canvas.createGraphicsShapes(200, 200);
Then I'd draw the content (in this case a circle):
g2d.setPaint(new Color(150,150,255));
g2d.setStroke(new BasicStroke(10.0f));
g2d.drawArc(50, 50, 100, 100, 0, 360);
Maybe I'd even wrap the canvas inside an image (that's not mandatory,
but it makes the math easier). Once this is done, I add the large
canvas to the smaller pages multiple times using different offsets:
img.setAbsolutePosition(0, -100);
document.add(img);
document.newPage();
img.setAbsolutePosition(-100, -100);
document.add(img);
document.newPage();
img.setAbsolutePosition(0, 0);
document.add(img);
document.newPage();
img.setAbsolutePosition(-100, 0);
document.add(img);
I hope this is more or less what you need, but please understand
that I made these examples based on assumptions. You didn't really
explain what you needed.
There's even a third solution. Bill Segraves made an application
called ScaleAndTile (Google will help you find it). It is used
to 'cut' a large PDF into 'manageable pages'. You could create
your tree on one giant page, then afterwards use functionality
as written by Bill to distribute the huge tree over different pages.
No virus found in this incoming message.
Checked by AVG.
Version: 8.0.100 / Virus Database: 269.24.4/1473 - Release Date: 29/05/2008 19:53