Bruno's
answer is absolutely correct in the general case. iText can't figure out
how tall the content of a given page is, but knows the precise dimensions of
each page. So adding pages whole is easy, but adding content is
all-but-impossible.
HOWEVER, if
your input is relatively fixed (each PDF will always be less than half a page
for example), then you can write some code that will draw those two pages on a
single page. I believe there's even a semi-related example on the examples
page...
Ah yes,
"TwoOnOne", the first "Manipulating existing PDF documents"
example:
It scales
two input pages down so they'll both fit on a single output page. In your
case, if you know they'll both fit when placed in some particular arrangement at
their original size, then by all means, do so. You can leave unfilled
portions of the source pages "hanging" outside the output pages visible
area. Perfectly legal.
The down
side of this approach is that if your input format ever changes, your output
will get Ugly. A page's content might be drawn on top of the other's, or
that content may continue off the bottom of the page.
If you're
generating these files yourself, you're in a better position. You can
embed the vertical height of the page's content in your initial pages to be
sucked up later and used for page positioning. Have a look at the "page
events" examples. You could write an EndPage handler that called
PdfWriter's getVeritcalPosition() and put that number in the documents 'info'
dictionary:
writer.getInfo().put( new PdfName("PageY"), new PdfNumber( verticalPos )
);
You could
then extract the information later with PdfReader's
getInfo():
PdfObject
yObj = reader.getInfo().get( new PdfName("PageY" ) );
float yPos =
((PdfNumber)yObj).floatValue();
In
production code you'd want some error checking of course (yObj !=
null && yObj.isNumber()).
--Mark
Storer
Senior Software Engineer
Cardiff Software
Senior Software Engineer
Cardiff Software
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----Bruno,
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Aymeric Alibert
Sent: Thursday, July 13, 2006 12:53 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] PDF concatenation without page break
> Hey, you have the same name as one of our princes (I live in the Kingdom
> of Belgium).
My wife is from Belgium too but she never told me about that. I need to dig that out...
> Concerning your question: PDF is not a Word Processing Format.
> It is a Page Description Languages: it describes what a page should look
> like.
> This implies that you can concatenate 'pages', but you can't concatenate
> 'content'
> and expect the layout to change accordingly.
> You will have a hard time finding a tool that does what you are looking for
> (I don't know of any).
> best regards,
> Bruno
>
That's the way I understood it, but I needed a confirmation. Thanks for the anwer,
Aymeric.
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
