Guide for VB.NET
Core Document Formats
Get to Start - Create, Load, Save
Additional Features

VB.NET PDF - How to Create, Load & Save PDF

Use .NET Document Library to Create, Load and Save PDF in VB.NET Programming

VB.NET
Home > .NET Imaging SDK > VB.NET > Get to Start with PDF
To get started with DocImage SDK for .NET, you are supposed to read VB.NET Imaging: Get Started first!

This page is designed to help users to get started with our standalone application VB.NET PDF document reading and editing SDK in high efficiency after you have finished downloading and installing RasterEdge .NET Imaging SDK on your PC.
By using this independent and mature VB.NET PDF getting started control, following questions will be handled rapidly without any third party component:
  • How to create and build a new PDF document with user-defined PDF pages count within VB.NET application?
  • I want to use image source to create a new PDF document, then how do I reach this target with your VB.NET PDF SDK?
  • How can I load and embed source PDF document from local file or memory to my VB.NET project?
  • After I have created or processed PDF document, in what way can I save my PDF file by using VB.NET methods?
If you want to get more VB PDF document viewing or editing functions, please see guide of VB.NET PDF reading SDK. And if you need the C#.NET PDF document getting started guide, please link to have a look.
How to Create - with Blank Page
Are you looking for a quite easy PDF creating and generating tool to allow for creating new PDF document with blank page? If so, you will work out this target just by using RasterEdge PDF document creating component within VB web or Windows application.

Creating API

Please refer to following simple API in VB class to create and build new PDF document containing blank PDF page. Moreover, the method, pageNum, will empowers you with the ability of imputing the PDF pages number manually.
Private Sub New(pageNum As Integer)
End Sub

Demo Code

Please check Visual Basic .NET sample code below to create an empty PDF document.
''' <summary>
''' Create an empty PDF document
''' </summary>
''' <param name="pageCount"></param>
''' <returns></returns>
Public Function CreatePDFDocument(pageCount As Integer) As PDFDocument
Return New PDFDocument(pageCount)
End Function
How to Create - with Image Source
If you have single or a couple of images and want to use these image source to create PDF file, you will need this PDF document building toolkit for VB.NET.

Sample Methods

Please use following demo methods to create a new PDF document which contains image(s) only.
PDFDocument(List < REImage > imageSource)
PDFDocument(List < REImage > imageSource, List < PDFCompression > compressions)
Method explanation: PDFDocument is the programming form of the loaded source PDF file. It contains PDF document reading and processing applications for VB.NET in the form of abstract. And PDFPage is used to stand for the specific PDFDocument functions for individual file page.

Demo Code

Please refer to Visual Basic .NET code below to create a new PDF file from image source. And we provide the most standard image compression mode to help your create an image-only-PDF document in high quality.
''' <summary>
''' Create PDF document object from image source
''' </summary>
''' <param name="images"></param>
''' <returns></returns>
Public Function CreateImageOnlyPDFDocumentDemo(images As List(Of REImage)) As PDFDocument
Return New PDFDocumentt(images)
End Function
How to Load
Our VB.NET PDF document loading library is a dynamic control without any dependency, like Adobe product. Use this reliable and optimized PDF loading tool to embed and load source PDF from both local file and memory stream.

Loading APIs

Following APIs and methods are written to load PDF document file from file path and memory stream in VB.NET program.
Private Function OpenDocumentFile(filePath As String, decoder As BaseDecoder) As REDocument Implements REFile.OpenDocumentFile
End Function
Private Sub New(s As Stream)
End Sub

Sample Code

Please check the Visual Basic .NET example code of loading PDF from file and loading PDF from memory respectively.
''' <summary>
''' Load PDF from stream
''' </summary>
''' <param name="s"></param>
''' <returns></returns>
Public Function LoadPDFDocumentFromStreamDemo(s As Stream) As PDFDocument
Dim doc As New PDFDocument(s)
Return doc
End Function

''' <summary>
''' Load PDF from file path
''' </summary>
''' <param name="filePath"></param>
''' <returns></returns>
Public Function LoadPDFDoucmentFromFileDemo(filePath As [String]) As PDFDocument
Return DirectCast(REFile.OpenDocumentFile(filePath, New PDFDecoder()), PDFDocument)
End Function
In addition, our VB.NET PDF document reading SDK still offers users the PDF document pages counting method to read and report PDF pages count as soon as you have loaded your PDF file. Besides, users are free to decide whether to activate and use this page getting function or not.

Page Count Getting API

Private Function GetPageCount() As Integer Implements PDFDocument.GetPageCount
End Function

Compliant Demo Code

''' <summary>
''' Get page count of an PDF doucment object
''' </summary>
''' <param name="doc"></param>
''' <returns></returns>
Public Function GetPageCount(doc As PDFDocument) As Integer
Return doc.GetPageCount()
End Function
How to Save
How to save the created or processed PDF document is also a vital issue considered by most of users. This VB.NET PDF document toolkit offers users two ways of storing PDF document just in the same ways as PDF loading, that is to say, saving PDF file to local file or storing to memory stream.

Saving Methods

Private Sub Save(filePath As [String]) Implements PDFDocument.Save
End Sub
Private Sub Save(s As Stream) Implements PDFDocument.Save
End Sub
Private Sub SaveDocumentFile(doc As REDocument, filePath As [String], decoder As BaseDecoder) Implements REFile.SaveDocumentFile
End Sub

Code to Save PDF to File

Example code below can be used to save PDF file to local file, and VB.NET users are able to define the file path freely.
''' <summary>
''' Save PDF document object to a PDF file
''' </summary>
''' <param name="doc"></param>
''' <param name="filePath"></param>

Public Sub SavePDFDocument(doc As PDFDocument, filePath As [String])
REFile.SaveDocumentFile(doc, filePath, New PDFEncoder())
' or you can use similar APIs:
' doc.Save(filePath);
End Sub

Code to Save PDF to Stream

Save PDF document in the form of memory stream by using following Visual Basic .NET sample code.
''' <summary>
''' Save PDF document to stream
''' </summary>
''' <param name="doc"></param>
''' <param name="s"></param>
Public Sub SavePDFDocument(doc As PDFDocument, s As Stream)
doc.Save(s)
End Sub


Recommend this to Google+