Depending on what you're trying to do it may be better to use
PdfStamper. In any case, the page has a crop box that must be taken into
account.
Paulo
> -----Original Message-----
> From: itext-questions-bounces@(protected)
> [mailto:itext-questions-bounces@(protected)
> Behalf Of DaveRussel@(protected)
> Sent: Sunday, July 15, 2007 10:41 PM
> To: itext-questions@(protected)
> Subject: [iText-questions] GetImportedPage shrink problem
>
> When I try and import the one page from the attached PDF
> file, using the code below, the output PDF file has top and
> bottom margins that do not match the input document. Is
> there anyway to get this to be an exact copy? I want to copy
> in the one page and then get the DirectContent and overlay.
>
> Thanks in advance.
>
> Here is the code:
>
> import
java.io.BufferedOutputStream;
> import
java.io.FileNotFoundException;
> import
java.io.FileOutputStream;
> import
java.io.IOException;
> import
java.net.URL;
>
> import
com.lowagie.text.Document;
> import
com.lowagie.text.DocumentException;
> import
com.lowagie.text.Rectangle;
> import
com.lowagie.text.pdf.BaseFont;
> import
com.lowagie.text.pdf.PdfContentByte;
> import
com.lowagie.text.pdf.PdfCopy;
> import
com.lowagie.text.pdf.PdfImportedPage;
> import
com.lowagie.text.pdf.PdfReader;
> import
com.lowagie.text.pdf.PdfWriter;
>
> public class TestPDFForm
> {
> private static final String INPUT_FORM = "TestInput.pdf";
>
> public TestPDFForm()
> {
> }
>
> public void createPDF() throws DocumentException, IOException
> {
> // Open the PDF file.
> URL url = this.getClass().getClassLoader().getResource(INPUT_FORM);
> PdfReader reader = new PdfReader(url);
>
> // Create a temporary file name.
> String strTempPdfFileName = "c:/TestOutput.pdf";
>
> // Create the new file.
> Rectangle psize = reader.getPageSize(1);
> Document document = new Document(psize);
> BufferedOutputStream bos =
> new BufferedOutputStream(new FileOutputStream(strTempPdfFileName));
> PdfWriter writer = PdfWriter.getInstance(document, bos);
> writer.setViewerPreferences(PdfWriter.PrintScalingNone);
> document.open();
>
> // Copy the pages to the new file.
> PdfContentByte cb = writer.getDirectContent();
>
> for (int i = 1; i <=reader.getNumberOfPages(); i++)
> {
> document.newPage();
> PdfImportedPage page = writer.getImportedPage(reader, i);
> cb.addTemplate(page, 0, 0);
> }
>
> document.close();
> writer.close();
> bos.close();
> }
>
> public static void main(String args[])
> {
> try
> {
> TestPDFForm form = new TestPDFForm();
> form.createPDF();
> System.out.println("Done...");
> System.exit(0);
> }
> catch( Throwable t)
> {
> t.printStackTrace();
> System.exit(1);
> }
> }
>
> }
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.