How to Start Convert PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

PDF VB.NET Library
How to read, extract, copy, paste PDF pages using VB.NET


Detailed VB.NET Guide for Extracting Pages from Microsoft PDF Document in VB.NET





In this Visual Basic .NET tutorial, you will learn how to read, manipulate PDF pages programmatically using VB.NET code.

  • Read, extract a PDF page, or multiple pages
  • Copy, paste PDF pages inside one PDF document, or among multiple PDF files
  • Clone PDF pages
  • Complate C# tutorial page at how to extract PDF pages using C#

How to read, extract PDF pages programmatically using VB.NET

  1. Download XDoc.PDF VB.NET library
  2. Install VB library to read, extract PDF pages
  3. Step by Step Tutorial












A good external PDF document page(s) extraction tool should be highly compatible with common Visual Studio versions, such as version 2005, 2008, 2010 or 2012, as well as .NET Framework (2.0 or above). Raster Edge XDoc.PDF SDK is such an extraction tool can be installed easily in VB.NET application, the extraction process will be greatly simplified. It provides a user-friendly interface, which is helpful to VB programmers to install and use the PDF page(s) extraction tool.

This .NET PDF Document Add-On integrates mature PDF document page processing functions, including extracting one or more page(s) from PDF document. To utilize the PDF page(s) extraction function in VB.NET application, you just need to initiate the granted license key and directly add RasterEdge.Imaging.Basic.dll and RasterEdge.Imaging.PDF.dll to your VB.NET project references. Then, you are capable of using the fully-designed APIs to extract certain page(s) from your PDF document in the VB.NET project.

Except provides PDF page extraction method in VB.NET, this page also gives VB.NET sample codes to copy and past PDF pages. Please refer to below listed demo codes.







How to Copy and Paste PDF Pages in VB.NET code?


The following VB.NET code will show how to copy pages from one PDF file, and paste them to another PDF file in VB.NET code.

  • Create two PDFDocument objects. One for source PDF file, and the other for target PDF file.
  • Read, extract the 2nd, 3rd, 5th three pages from the source PDF document object
  • Insert the above three PDF pages to the target PDF document at the 3rd page position
  • Save the new PDF document into file



' get a PDFDocument object
Dim inputFilePath1 As String = "C:\1.pdf"
Dim doc1 As PDFDocument = New PDFDocument(inputFilePath1)
' get another PDFDocument object
Dim inputFilePath2 As String = "C:\2.pdf"
Dim doc2 As PDFDocument = New PDFDocument(inputFilePath2)

' duplicate the 2nd page, 3rd page And 5th page from the first document
Dim pageIndexes As Integer() = New Integer() {1, 2, 4}
Dim pages As BasePage() = doc1.DuplicatePages(pageIndexes)

' insert pages to the second document at the specified position
Dim pageIndex As Integer = 2
doc2.InsertPages(pages, pageIndex)

' output the New document
Dim outputFilePath As String = "C:\output.pdf"
doc2.Save(outputFilePath)




Copy and Replace PDF Pages using VB.NET


' load the PDF file that provides the page object 
Dim resFilePath As String = Program.RootPath + "\\" + "2.pdf"
Dim resDoc As PDFDocument = New PDFDocument(resFilePath)
' get the 1st page in the document
Dim page As PDFPage = resDoc.GetPage(0)

' get PDFDocument object from a source file
Dim inputFilePath As String = Program.RootPath + "\\" + "1.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' replace the 3rd page by the PDFPage object
Dim pageIndex As Integer = 2
doc.UpdatePage(page, pageIndex)

' save the PDFDocument
Dim outputFilePath As String = Program.RootPath + "\\" + "Output.pdf"
doc.Save(outputFilePath)




VB.NET: How to extract PDF pages and overwrite the original PDF file


' get PDFDocument object from a source file
Dim inputFilePath As String = "C:\1.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' select pages
Dim pageIndexes As List(Of Integer) = New List(Of Integer)
' the 3rd page
pageIndexes.Add(2)
' the 1st page
pageIndexes.Add(0)
' the 4th page
pageIndexes.Add(3)
' create the new document with 3 pages
Dim newDoc As PDFDocument = doc.GetMultiDocument(pageIndexes)

' save the PDFDocument
newDoc.Save(inputFilePath)




Extract PDF pages and save into a new PDF file using VB.NET


You can easily read and extract a PDF page or multiple pages using Visual Basic .NET. Below are the steps and VB.NET example source code to extract PDF pages.

  • Create a PDFDocument object with a PDF file loaded
  • Read, extract the 3rd, 1st, 4th three pages from the PDF document object
  • Create a new PDF document object with the three pages, and save to a PDF file



' get PDFDocument object from a source file
Dim inputFilePath As String = "C:\1.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' select pages
Dim pageIndexes As List(Of Integer) = New List(Of Integer)
' the 3rd page
pageIndexes.Add(2)
' the 1st page
pageIndexes.Add(0)
' the 4th page
pageIndexes.Add(3)
' create the new document with 3 pages
Dim newDoc As PDFDocument = doc.GetMultiDocument(pageIndexes)

' save the PDFDocument
Dim outputFilePath As String = "C:\Output.pdf"
newDoc.Save(outputFilePath)






Clone a PDF Page in VB.NET


You can duplicate any of PDFDocument page and get a new PDFPage, and then do further manipulations with the code below.

  • Create a PDFDocument object with an existing PDF file loaded
  • Duplicate the second page of the PDF document



' get PDFDocument object from a source file
Dim inputFilePath As String = "C:\1.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' duplicate the second page in the document
Dim pageIndex As Integer = 1
Dim page As PDFPage = doc.DuplicatePage(pageIndex)

' do something ...