Write database to PDF file
A file with .pdf file extension is called Portable Document Format(PDF) file. Nowadays businesses and government agencies around the world use Portable Document Format(PDF) as a standard format for exchanging documents more securely. PDF File format allows us a page-by-page view of documents, exactly as they appear in their printed form. There is a usual question that how to read data from a database using sql statements and write that data to a PDF document.
PDFsharp is an open source library that allows developers to create and manipulate PDF documents. PDFsharp enables developers looking to enhance their applications with dynamic PDF document creation and manipulation.
You can download .Net PDFsharp library from the following link: Download PDFsharp Assemblies
After download the zip file, extract it and add the reference to your vb.net project
If you are not familiar with how to add reference and create pdf file, just follow the link : How to create PDF file programmatically
Write sql result to pdf file
Before creating PDF file we should read the data from database using sql query string. So we should create and initialize a connection string and sql statement.
Write data from Dataset to pdf file
After make the connection, select the data from database using sql query and store it in a Dataset.
Now we have data from the database, next step is to create and initialize Pdfsharp object to crate a new pdf file for writing the retrieved data.
Now you can write the data to the pdf file.
After write the data to the pdf file you should save the file with .pdf extension.
Now you can open the newly created pdf file, the output is look like the following picture.
The following VB.Net source code shows how to retrieve the data from database and write to the pdf file.
- How to VB.NET Directory operations
- How to VB.NET File operations
- How to VB.NET FileStream
- How to VB.NET TextReader
- How to VB.NET Simple TextReader
- How to VB.NET TextWriter
- How to VB.NET BinaryReader
- How to VB.NET BinaryWriter
- How to convert xps file to bmp file
- How to VB.Net Path Class
- How to create PDF files in vb.net
- How to convert text file to pdf