VB.NET PDF: How to HTML5 PDF Viewer PDF Create PDF Export File & Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF PDF Viewer Work with Other SDKs Barcode Read Barcode Create OCR Twain
Page: Extract, Copy, Paste PDF Pages
  |  
Home ›› XDoc.PDF ›› VB.NET PDF: Copy and Paste PDF Page

VB.NET PDF - PDF File Pages Extraction Guide in VB.NET


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



Look for HTML5 PDF Editor?

EdgePDF: ASP.NET PDF Editor is the best HTML5 PDF Editor and ASP.NET PDF Viewer based on XDoc.PDF, JQuery, HTML5. It supports ASP.NET MVC and WebForms projects.


Free VB.NET PDF document manipulation SDK library compatible with Visual Studio and .NET framework 2.0+


Help to extract single or multiple pages from adobe PDF file and save into a new PDF file in Visual Basic .NET class


Ability to copy PDF pages and paste into another PDF file in .NET Windows Forms application and ASPX webpage


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


Security .NET PDF component download


Online source codes for quick evaluation in VB.NET class


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.




VB.NET DLLs: Extract, Copy and Paste PDF Page



In order to run the sample code, the following steps would be necessary.


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.XDoc.Raster.dll


  RasterEdge.XDoc.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;




VB.NET: Extract All Images from PDF Document



This is an example that you can use it to extract all images from PDF document.




' Get page 3 from the document.
Dim page As PDFPage = doc.GetPage(3)

' Select image by the point (50F, 100F).
Dim img As PDFImage = PDFImageHandler.SelectImage(page, New PointF(50.0F, 100.0F))





VB.NET: Clone a PDF Page



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




Dim filepath As String = ""
Dim outPutFilePath As String = ""
Dim doc As PDFDocument = New PDFDocument(filepath)

' Copy the first page of PDF document.
Dim page As PDFPage = doc.DuplicatePage(1)

' Do further manipulations ...





VB.NET: Copy and Paste PDF Pages



VB.NET programming example below will show you how to copy pages from a PDF file and paste into another one.




' Copy three pages from test1.pdf and paste into test2.pdf.
Dim pdf As PDFDocument = New PDFDocument("C:\test1.pdf")
Dim pdf2 As PDFDocument = New PDFDocument("C:\test2.pdf")
Dim pageindexes = New Integer() {1, 2, 4}
Dim pages = pdf.DuplicatePage(pageindexes)
pdf2.InsertPages(pages, 2)





VB.NET: Copy and Replace PDF Pages



Use the following example code in your VB.NET application to copy pages from a PDF file and replace pages in another file accordingly.




' 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: Extract PDF Pages and Save into a New PDF File



You can easily get pages from a PDF file, and then use these pages to create and output a new PDF file. Pages order will be retained.




' Get PDFDocument object from a source file.
Dim inputFilePath As String = Program.RootPath + "\\" + "1.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Select pages.
Dim pageIndexes As New List(Of Integer)
pageIndexes.Add(2)  ' The 3rd page.
pageIndexes.Add(0)  ' The 1st page.
pageIndexes.Add(3)  ' The 4th page.

' Create the new document with 3 pages.
Dim newDoc As PDFDocument = doc.GetMultiDocument(pageIndexes)

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





VB.NET: Extract PDF Pages and Overwrite the Original PDF File



Instead of outputting a new PDF file, you may also overwrite the original PDF file.




' Get PDFDocument object from a source file.
Dim inputFilePath As String = Program.RootPath + "\\" + "1.pdf"
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Select pages.
Dim pageIndexes As New List(Of Integer)
pageIndexes.Add(2)  ' The 3rd page.
pageIndexes.Add(0)  ' The 1st page.
pageIndexes.Add(3)  ' The 4th page.

' Create the new document with 3 pages.
Dim newDoc As PDFDocument = doc.GetMultiDocument(pageIndexes)

' Save the PDFDocument.
Dim outputFilePath As String = Program.RootPath + "\\" + "1.pdf"
newDoc.Save(outputFilePath)





VB.NET: Extract All Images from PDF Document



This VB.NET code below can help you extract all images from PDF.




' Open a document.
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Extract all images in the document.
Dim allImages As List(Of PDFImage) = PDFImageHandler.ExtractImages(doc)

' Extract all images in page 2.
Dim page As PDFPage = doc.GetPage(2)
Dim allImagesInPage As List(Of PDFImage) = PDFImageHandler.ExtractImages(page)

' ...