Write database data to pdf file
A file with .pdf file extension is called PDF (Portable Document Format) file. Nowadays PDF files are frequently used in important documents such as tax papers, bank statements, and other forms of documents that require the user to fill in data. 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 the Open Source library for creating and modifying Adobe PDF documents programmatically.
You can freely download the Assemblies version from the following link: Download PDFsharp Assemblies
After download the zip file, extract it and add the reference to your c# project.
If you want to know the step by step tutorial on how to create your first pdf file programmatically, follow the link : How to create PDF file programmatically
Write sql result to pdf file
Here we are using Pdfsharp library to generate the PDF document, before that we have to read the data from Database. So we create connection string and sql for doing this.
Write data from Dataset to pdf file
Retrieve the data and store it n a Dataset.
The next step is to create and initialize the PDFSharp Object to create the pdf document.
Finally we retrieve each row from the dataset and write to the pdf file.
output sample display
The following C# source code shows how to retrieve the data from database and write to the pdf file.
- How to use C# Directory Class
- How to use C# File Class
- How to use C# FileStream Class
- How to use C# Textreader Class
- A simple C# Text Reader source code
- How to use C# TextWriter Class
- How to use C# BinaryWriter Class
- How to use C# BinaryReader Class
- How to convert XPS file to Bitmap
- How to C# Path Class
- How to create a pdf file in C#
- How to create PDF file from Text file