How to read PDF file in C#, VB.NET?
PDF (Portable Document Format) is a file format used to display the document with same formatting, independent of application software, hardware, and operating system. Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can read an existing PDF file and save it in C# and VB.NET.
Steps to read a PDF file programmatically:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework applications from NuGet.org.
- Include following namespaces in Program.cs file.
C#
using Syncfusion.Pdf.Parsing; using System;
VB.NET
Imports Syncfusion.Pdf.Parsing Imports System
- Use the following code snippet to read an existing PDF file.
C#
//Load the document PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf"); //Access the document information //Author string Author = document.DocumentInformation.Author; //Creation date DateTime CreatedOn = document.DocumentInformation.CreationDate; //Creator string Creator = document.DocumentInformation.Creator; //Keywords string Keyword = document.DocumentInformation.Keywords; //Subject or description string Subject = document.DocumentInformation.Subject; //Title string Title = document.DocumentInformation.Title; //Close the document document.Close(true);
VB.NET
'Load the document Dim document As PdfLoadedDocument = New PdfLoadedDocument("Sample.pdf") 'Access the document information 'Author Dim Author As String = document.DocumentInformation.Author 'Creation Date Dim CreatedOn As DateTime = document.DocumentInformation.CreationDate 'Creator Dim Creator As String = document.DocumentInformation.Creator 'Keywords Dim Keyword As String = document.DocumentInformation.Keywords 'Subject or description Dim Subject As String = document.DocumentInformation.Subject 'Title Dim Title As String = document.DocumentInformation.Title 'Close the document document.Close(True)
A complete working sample along with the input file used can be downloaded from Read-PDF-file.zip
Take a moment to peruse the documentation, where you can find other options like drawing right-to-left text and multi-column text, consuming TrueType fonts, Standards fonts, CJK fonts. Also, the features like PDF form filling, extract text or images from PDF, protect PDF documents with code examples.
Refer here to explore the rich set of Syncfusion Essential PDF features.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning about how to read PDF file in C#, VB.NET.
You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!