Copy document by page to insert blank page in between using iTextsharp

Casey

How to add a new page between every page and then copy over to a new PDF. I know I am missing something basic, but am not seeming to get it down correctly.

        int n = pdfReaderInput.NumberOfPages;
        Document document = new Document(); 

        PdfCopy copy = new PdfCopy(document, new FileStream(tempFile, FileMode.OpenOrCreate)); 
        document.Open();
        for (int i = 0; i < n; )
        {
            copy.AddPage(copy.GetImportedPage(pdfReaderInput, ++i));
        }

        document.Close();

        return tempFile;

I understand and know this is wrong, but am not sure what I need to do. basically, I am adding a blank pdf in between every page. Thanks in advance!

Bruno Lowagie

When using PdfCopy (or its subclass PdfSmartCopy), you can use the addPage() method like this:

copy.addPage(PageSize.A4, 0);

In this case, a page with size A4 will be added. If you want to make sure that the blank page has the same dimensions as another pages in your document (for instance page 1), you'll do something like this:

copy.addPage(reader.getPageSize(1), reader.getPageRotation(1));

The Rectangle value will now correspond with the size of the first page in the reader; the int value will correspond with the rotation of the first page of your existing document.

Update: I now see that you marked your question with the [itext] as well as the [itextsharp] tag. I answered it under the [itext] tag using Java code. It goes without saying that this answer is also valid for iTextSharp, but you'll need to make some minor updates to the syntax, for instance change addPage() into AddPage().

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

iTextSharp insert a page at the beginning

From Dev

document.write blank page

From Dev

Copy a visio page to a new document

From Dev

dompdf inserts blank page at end of document

From Dev

Is it possible to convert PDF page to Image using itextSharp?

From Dev

Bookmark to specific page using iTextSharp 4.1.6

From Dev

Blank Page after executing insert query in codeigniter

From Dev

itextsharp setting trimbox does not work on first page in my document

From Dev

itextsharp setting trimbox does not work on first page in my document

From Dev

insert new page between existing pages in pdf using matplotlib in python

From Dev

iTextSharp vertical page fill

From Dev

Header of Page with iTextSharp

From Dev

Getting blank page using RequireJS and Grunt

From Dev

Redirect page displays blank when using $_POST

From Dev

PDF is blank page when using CGPDFContextCreateWithURL

From Dev

Find location last object on PDF page using iTextSharp

From Dev

how to add pagenumbers to every pdf page using itextsharp

From Dev

Insert blank page after each record in Crystal Report

From Dev

How do I insert a blank page into a PDF with ghostscript or pdftk?

From Dev

How to make "document.write" in an if statement work on the same html page rather than a new blank page?

From Dev

iTextSharp - PDF Bookmark not pointing to a page

From Dev

iTextSharp: Header on only First Page

From Dev

Getting "An error exists on this page. Acrobat may not display the page correctly." using ITextSharp WriteSelectedRows

From Dev

PDFBox - copy only the page resources instead of copying all resources of a document

From Dev

save copy of existing remote page using php

From Dev

PHP - how to copy a file using a page like this?

From Dev

Insert page headers/footers when printing HTML document

From Dev

Word Interop C#: Insert new page using existing page

From Dev

Using Javascript to insert css link into the head of a page

Related Related

  1. 1

    iTextSharp insert a page at the beginning

  2. 2

    document.write blank page

  3. 3

    Copy a visio page to a new document

  4. 4

    dompdf inserts blank page at end of document

  5. 5

    Is it possible to convert PDF page to Image using itextSharp?

  6. 6

    Bookmark to specific page using iTextSharp 4.1.6

  7. 7

    Blank Page after executing insert query in codeigniter

  8. 8

    itextsharp setting trimbox does not work on first page in my document

  9. 9

    itextsharp setting trimbox does not work on first page in my document

  10. 10

    insert new page between existing pages in pdf using matplotlib in python

  11. 11

    iTextSharp vertical page fill

  12. 12

    Header of Page with iTextSharp

  13. 13

    Getting blank page using RequireJS and Grunt

  14. 14

    Redirect page displays blank when using $_POST

  15. 15

    PDF is blank page when using CGPDFContextCreateWithURL

  16. 16

    Find location last object on PDF page using iTextSharp

  17. 17

    how to add pagenumbers to every pdf page using itextsharp

  18. 18

    Insert blank page after each record in Crystal Report

  19. 19

    How do I insert a blank page into a PDF with ghostscript or pdftk?

  20. 20

    How to make "document.write" in an if statement work on the same html page rather than a new blank page?

  21. 21

    iTextSharp - PDF Bookmark not pointing to a page

  22. 22

    iTextSharp: Header on only First Page

  23. 23

    Getting "An error exists on this page. Acrobat may not display the page correctly." using ITextSharp WriteSelectedRows

  24. 24

    PDFBox - copy only the page resources instead of copying all resources of a document

  25. 25

    save copy of existing remote page using php

  26. 26

    PHP - how to copy a file using a page like this?

  27. 27

    Insert page headers/footers when printing HTML document

  28. 28

    Word Interop C#: Insert new page using existing page

  29. 29

    Using Javascript to insert css link into the head of a page

HotTag

Archive