XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Page: Insert PDF Pages
  |  
Home ›› XDoc.PDF ›› C# PDF: Insert PDF Page

How to insert pages into Adobe PDF document in C#.NET


Full featured C# source code to insert pages into PDF files using XDoc.PDF for .NET library. Free Online Trail Download.




Best C#.NET PDF SDK for inserting PDF pages in Visual Studio .NET framework


Free .NET evaluation library for adding pages to adobe PDF in both .NET WinForms application and ASPX webpage


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


C#.NET source code for inserting a single one page or multiple pages to PDF document in .NET console application


Able to create a blank PDF page in both web server-side application


C#.NET users can insert a PDF page from a supported file format


Ability to add PDF page number in preview


Offer PDF page break inserting function


C#.NET PDF document editor library control, RasterEdge XDoc.PDF, offers easy & mature APIs for developers to add & insert an (empty) page into an existing PDF document file. Besides, this PDF document page inserting library control toolkit allows developers to specify where they want to insert (blank) PDF document page (before the first page or after the last page or after any desired page of current PDF document) using C# .NET class code.


This C# .NET PDF document page inserting & adding component from RasterEdge is written in managed C# code and designed particularly for .NET class applications. Thus, using this PDF document page manipulating and processing control SDK, you can create & add new PDF page(s) to current target PDF document in both web server-side application and Windows Forms project using a few lines of simple C# code.


Apart from the ability to inserting a new PDF page into existing PDF document file, RasterEdge C# .NET PDF document page processing and editing control toolkit also owns other advanced PDF document page manipulating functions. RasterEdge offers detailed guidances for each of those page processing functions, such as how to merge PDF document files by C# code, how to rotate PDF document page, how to delete PDF page using C# .NET, how to reorganize PDF document pages and how to split PDF document in C# .NET class application.


By using reliable APIs, C# programmers are capable of adding and inserting (empty) PDF page or pages from various file formats, such as PDF, Tiff, Word, Excel, PowerPoint, Bmp, Jpeg, Png, Gif, and so on. Some C# demos are provided for your reference.





C# add a blank page to specified pdf position


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




        #region add a blank page to specified pdf position
        internal static void insertBlankPageToPdf()
        {
            String filepath = @"";
            String outPutFilePath = @"";
            PDFDocument doc = new PDFDocument(filepath);

            // Insert an empty page at 2 (previous to the third page).
            doc.AddEmptyPage(2);

            // Save the file.
            doc.Save(outPutFilePath);
        }
        #endregion




C# add an existing pdf page to the specified pdf page position





        #region add an existing pdf page to the specified pdf page position
        internal static void insertExistingPageToPdf()
        {
            String inputFilePath1 = @"C:\1.pdf";
            String inputFilePath2 = @"C:\2.pdf";
            String outPutFilePath = @"C:\Output.pdf";

            PDFDocument doc1 = new PDFDocument(inputFilePath1);
            PDFDocument doc2 = new PDFDocument(inputFilePath2);

            // Get a page from the first document.
            PDFPage page = (PDFPage)doc1.GetPage(0);

            // Specify a position for inserting the selected page.
            int pageIndex = 2;

            // Insert the page to the second document at specified position.
            doc2.InsertPage(page, pageIndex);

            // Output the new document.
            doc2.Save(outPutFilePath);
        }
        #endregion




C# add list of existing pdf pages to the specified pdf page position





        #region add list of existing pdf pages to the specified pdf page position
        internal static void insertExsitingPagesToPdf()
        {
            String inputFilePath1 = @"C:\1.pdf";
            String inputFilePath2 = @"C:\2.pdf";
            String outPutFilePath = @"C:\Output.pdf";

            PDFDocument doc1 = new PDFDocument(inputFilePath1);
            PDFDocument doc2 = new PDFDocument(inputFilePath2);

            // Get page 0, page 1 and page 2 from the first document.
            PDFPage page0 = (PDFPage)doc1.GetPage(0);
            PDFPage page1 = (PDFPage)doc1.GetPage(1);
            PDFPage page2 = (PDFPage)doc1.GetPage(2);
            PDFPage[] pages = new PDFPage[3] { page0, page1, page2 };

            // Specify a position for inserting the selected pages.
            int pageIndex = 1;

            // Insert the pages to the second document at specified position.
            doc2.InsertPages(pages, pageIndex);

            // Output the new document.
            doc2.Save(outPutFilePath);

        }
        #endregion




.NET Class Namespace Required



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;





public override void AddPage(BasePage page)

Description:
     Add a PDF page into PDF file at default position, first page number.

Parameters:



public override void AddPage(BasePage[] pages)

Description:
     Add PDF pages into PDF file at default position, first page number.

Parameters:



public override void InsertPage(BasePage page, int pageIdx)

Description:
     Insert a PDF page into PDF file at specifiec position through page index.

Parameters:



public override void InsertPage(BasePage[] pages, int pageIdx)

Description:
     Insert PDF pages into PDF file at specifiec position through page index.

Parameters:



public int AddEmptyPage(int pageIndex)

Description:
     Add a blank page to PDF file at specified position.

Parameters:

Return:
     Error code, 0 if success.



public int AddEmptyPage(int pageIndex, PaperSize pageSize)

Description:
     Add a blank page with specified size to PDF file at specified position.

Parameters:

Return:
     Error code, 0 if success.



public int AddEmptyPages(int startPageIndex, int count)

Description:
     Add continuous blank pages to PDF file at specified position.

Parameters:

Return:
     Error code, 0 if success.



public int AddEmptyPages(int startPageIndex, int count, PaperSize pageSize)

Description:
     Add continuous blank pages to PDF file at specified position.

Parameters:

Return:
     Error code, 0 if success.



public void InsertPage(int pageIdx)

Description:
     Add a blank page to PDF file at specified position.

Parameters:



public void InsertPage(int pageIdx, PaperSize pageSize)

Description:
     Add a blank page with specified size to PDF file at specified position.

Parameters: