ITEXTSHARP DATASET TO PDF

It is a common question that comes to every programmer after populating their tables from the database, how can we export this table into PDF? The answer is pretty clear. We can do this easily using the iTextSharp library in C. To incorporate iTextSharp into our project, we need to download the. After downloading and importing the required files, the first thing we have to do is to import 2 libraries to our C project.

Author:Akizshura Shakabar
Country:Moldova, Republic of
Language:English (Spanish)
Genre:Spiritual
Published (Last):10 March 2014
Pages:371
PDF File Size:10.93 Mb
ePub File Size:11.47 Mb
ISBN:211-3-84378-883-7
Downloads:63178
Price:Free* [*Free Regsitration Required]
Uploader:Zolokree



It is a common question that comes to every programmer after populating their tables from the database, how can we export this table into PDF? The answer is pretty clear. We can do this easily using the iTextSharp library in C. To incorporate iTextSharp into our project, we need to download the. After downloading and importing the required files, the first thing we have to do is to import 2 libraries to our C project. Then add the following namespace to your code.

Next thing we have to do is to set the page size of the PDF. There are several sizes we can use with the iText library. For an example, we can use A4, A3, A6, Letter etc. Further details about page sizes can be found on the official documentation of the iText. Link to it is given below for further reading. In this example, I am going to use the Letter page sizing with customized margins.

For that, we need to create a document object as we are going to create a PDF from scratch. After creating the document object, we need to specify the new pdf by creating a PdfWriter instance by applying the custom size document we created earlier. For that iText provides a default method which takes 2 arguments; one which is the document object we created and the other one is the new file stream.

By using FileMode. In here we use symbol to make sure that new PDF is created in the absolute location of the project; i. But if you want to create it in a different location, we can specify the relative path as well. So far we have created an empty pdf file. For that, we can use the Rectangle object provided by the iTextSharp. By now we have added a border to our PDF. The great thing about this library is that we can customize everything as we wish.

Next, we will set the font styles of the document and add a logo to the pdf file. For each of these iTextSharp provides default methods and we can use them and do the customization as we wish. Next section is the most important part of the exporting. For that, we will create an object from the PdfPTable and assign the number of columns in the DataTable.

After that, we need to create table cells for each of the columns we specified. For that, we need to iterate through the data of the dataTable and insert them into the document. We can use this code inside a method and call it from anywhere you want.

For an example, we can call the method to a click event of a button and export the data into PDF file and save it in a path you specified. Introduction to Stack in C. NET using C. Tutorials Panel written 1 year ago. Facebook Twitter LinkedIn. In this article. Note: it is really important to close the document as it can cause stack overflow errors unless it is closed at the end.

BS4999 PDF

How can we export datatable to PDF using iTextSharp

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more. Ask Question.

SANTA SANGRE SANTO GRIAL PDF

How can we export datatable to PDF using iTextSharp

In this article I am explaining how to achieve the same in ASP. For this tutorial I am using NorthWind Database which can be downloaded from here. Once that is downloaded you can attach the same to your SQL Server. Connection String. Below is my connection string to the database. Imports System. Imports iTextSharp.

LOIC WACQUANT BODY AND SOUL PDF

Datatable To PDF In C#

.

TDA8944J PDF

Subscribe to RSS

.

Related Articles