On 17/08/2012 12:19, cmo wrote:
> Why is it, that a PdfCopy/SmartCopy doe's not worry about paper sizes and
> rotations when adding
> an imported page via copy.addPage(page) and

You mean that PdfCopy/SmartCopy preserve the page boundaries and 
rotation (so they do worry about paper size and rotation).

> a writer does worry via
> writer.addtemplate(page).

PdfWriter doesn't worry about the rotation (it doesn't look at the 
rotation key in the MediaBox). As for the page size, it only looks at 
the MediaBox and not at the other page boundaries (in your case: it 
doesn't worry about the CropBox).

> Why im asking this?

Good question. We want to avoid that people use PdfWriter / 
PdfImportedPage for the purpose of concatenating PDFs, and that's why 
PdfWriter worries less about page boundaries and rotation than 
PdfStamper, PdfCopy and PdfSmartCopy.

> My problem is, that i want to merge pages

Merge: PdfCopy / PdfSmartCopy

> but also scale them down

Why? PDF files don't have a resolution. In Adobe Reader, you can zoom 
in, zoom out, and you have different print options. I've never 
understood the arguments people forward when they say "we want to scale 
down a PDF." Maybe you'll be the first one providing me a good argument, 
so I'm curious to read on.

> and have
> them exceute a custom
> PdfPageEventHelper so that I get the same page, a little smaller with header
> and footer.

Aha, what you actually want to do, is to change the page boundaries so 
that you can add extra content. Are you sure that implies scaling down 
the document? Because it won't be sufficient to scale down the content, 
you'll also have to scale down all the interactive features (otherwise 
all the links and annotations will end up on the wrong place; actually 
when using PdfWriter, all interactivity will get lost completely).

> It seems Copy/Smart does not trigger the OnEndPageEvent()

please start by downloading chapter 6 of the book "iText in Action - 
Second Edition": http://www.manning.com/lowagie2/samplechapter6.pdf

Now read p188 (the 36th page in the extract of the book):

ADDING CONTENT WITH PDFCOPY
In previous sections, I explained that PdfImportedPage is a read-only 
subclass of PdfTemplate. You can’t add any content to an imported page. 
This wasn’t a big deal when using imported pages with PdfWriter and 
PdfStamper because we could easily add content over or under the 
imported page. When using PdfCopy, it would be interesting if we could 
somehow add extra content too.

What this paragraph says is basically that PdfCopy and its subclass 
PdfSmartCopy are for read-only use only, which explains why the 
following line has no effect:
copy.setPageEvent(new WatermarkCreator("DRAFT"));
I'll make sure an Exception is thrown when using this method in the next 
release of iText.

> and can't scale
> the imported page.

But you don't want to scale down the imported page: you just want to 
create some extra space for a header and a footer! Typically, you'll do 
that by changing the rectangles defining the page boundaries at the 
level of PdfReader. This is an example that does the opposite: 
http://1t3xt.be/?104
It 'crops' pages (makes them smaller). You need to update the example to 
make pages bigger.

> So I have to use the Writer and addtemplate(page, matrix) to get the desired
> result.

Ouch, yes, that's to be used only in the case the 'good solution' 
doesn't meet your requirements. For instance: because you discover that 
your document had invisible content that was cropped and that is visible 
after removing the cropping.

> There lies my problem -  now it seems I have to worry about paper sizes and
> rotation.

Yes, you do. See page 167 of the chapter you've just downloaded (the 
last code snippet of section 6.2.1).
You have to ask the page for its rotation, and in your case, you need 
this to define the rotation of the new page you're creating.

> Rotations/scaling I can handle with a matrix, but the resulting pages does
> not have the same size as the imported page.

The MediaBox is the same, but did you check the other page boundaries? 
Especially the CropBox deserves your attention.

> How do I set them to match the source page size. When using
>    document.setPageSize(importedPage.getSize());
>    document.newPage();

That's not sufficient is it? You're copying the MediaBox (getSize() / 
setSize()), but not the other page boundaries.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to