Convert to PDF from .NET project
Published: 15 June 2020
By: Rustemsoft
You probably have for some time wanted a .NET component solution for converting some data source files like Excel, Access mdb database, or text file into PDF documents during an automatic build process of a software product.
Introduction
As a rule, your customers like the PDF format and so do a heck of a lot of other people. It is as close to an “alternative standard” as you can get. It might not be used for everything, but what it is used for - it is used well. How would you like to be able to convert to PDF right from your .NET application?
ExportToPDF .NET assembly
ExportToPDF is .NET library that offers the ability to convert csv files, Excel spreadsheets, Access mdb databases, text files, .NET DataTable objects to PDF on the fly. If you need PDF reports you do not have to use complex report generators anymore. Just create a simple .NET Windows Form or ASP.NET page and export it to PDF with the ExportToPDF assembly. You can set PDF page margins, change page orientation (portrait, landscape), customize headers and footers (change fonts, colors), add page numbers and more. ExportToPDF .NET assembly can be used as general purpose component for converting data source files to PDF documents or it can be used to create PDF reports directly from .NET applications to benefit from the great power of standard .NET databound server controls. You can add footers and headers to the rendered document, set the page size, page orientation and more PDF settings. The ExportToPDF assembly can be used from any .NET (2.0 or later) application (Windows forms, ASP.NET Web sites or command line tools). ExportToPDF is a PDF development .NET assembly designed to help you develop PDF conversion .NET application with very minimum efforts. It takes several lines of codes to generate PDF file from a data source like CSV, Excel, text file, Access database, .NET DataTable object and complete your programming project. ExportToPDF.dll is a .NET assembly for developers to implement conversion to PDF process software solutions.
PDF Converter sample project
We have built the trial sample PDF Converter project that demonstrates the use of the Export to PDF class and show the results of using the class in several examples.
As you can see on the above figure the sample converter application interface allows you to select data source type you are going to convert. Also it gives you ability to adjust formatting, PDF content merging, font settings, text coloring and other PDF tasks. Download the sample PDF Converter VB.NET and C# projects.
How to convert SQL Server database query to PDF?
ExportToPDF is helpful to export your SQL Server query result into a formatted PDF file. For this case SourceType property of Rustemsoft.ExportToPDF.Export class object has to be signed as SourceTypes.DataTable. Then the SQL query result should be populated to System.Data.DataTable object. ExportToPDF just converts the DataTable object to PDF.
VB .NET Imports System.Data Imports Rustemsoft.ExportToPDF Imports System.Data.SqlClient ... Dim ExportToPDFobject As New Rustemsoft.ExportToPDF.Export Dim Connection As String = "Initial Catalog=[MyDatabaseName];Data Source=[MySQLServerName];UID=[MyUserID];PWD=[psw]" Dim conn As New SqlConnection(Connection) conn.Open() Dim strSQL As String = "SELECT * from MyTable" Dim cmdMyTable As New SqlCommand(strSQL, conn) cmdMyTable.CommandType = CommandType.Text cmdMyTable.CommandTimeout = 6000 ' Create a SqlDataAdapter for the MyTable table Dim tblMyTable As DataTable = New DataTable Dim adpMyTable As SqlDataAdapter = New SqlDataAdapter adpMyTable.SelectCommand = cmdMyTable adpMyTable.Fill(tblMyTable) ExportToPDFobject.SourceType = SourceTypes.DataTable ExportToPDFobject.DataSourceTable = tblMyTable ExportToPDFobject.outputFileName = "C:\MyDirectory\MyTable.pdf" ' Assign specific ExportToPDFobject's PDF formatting, coloring, and others properties ... ' Run conversion to PDF ExportToPDFobject.Convert() conn.Close()
C# using System.Data; using Rustemsoft.ExportToPDF; using System.Data.SqlClient; ... Rustemsoft.ExportToPDF.Export ExportToPDFobject = new Rustemsoft.ExportToPDF.Export(); string Connection = "Initial Catalog=[MyDatabaseName];Data Source=[MySQLServerName];UID=[MyUserID];PWD=[psw]"; SqlConnection conn = new SqlConnection(Connection); conn.Open(); string strSQL = "SELECT * from MyTable"; SqlCommand cmdMyTable = new SqlCommand(strSQL, conn); cmdMyTable.CommandType = CommandType.Text; cmdMyTable.CommandTimeout = 6000; // Create a SqlDataAdapter for the MyTable table DataTable tblMyTable = new DataTable(); SqlDataAdapter adpMyTable = new SqlDataAdapter(); adpMyTable.SelectCommand = cmdMyTable; adpMyTable.Fill(tblMyTable); ExportToPDFobject.SourceType = SourceTypes.DataTable; ExportToPDFobject.DataSourceTable = tblMyTable; ExportToPDFobject.outputFileName = "C:\\MyDirectory\\MyTable.pdf"; // Assign specific ExportToPDFobject's PDF formatting, coloring, and others properties ... // Run conversion to PDF ExportToPDFobject.Convert(); conn.Close();
Summary
ExportToPDF provides a single API class with a bunch of very customizable properties to create, manipulate, and organize PDF documents from within your .NET applications. Rustemsoft presents the 'file to PDF' conversion package, named ExportToPDF .NET assembly that accomplishes conversion, formatting, PDF content merging, font settings, text coloring and other PDF tasks.