How To Generate And Download Pdf Report From Database In Mvc Using Itextsharp C

0 views
Skip to first unread message

Niki Debruin

unread,
Jan 9, 2024, 5:37:36 AM1/9/24
to fadamsmighdist
EDIT 2:
The purpose is to create a report with some data in a database. The data in a database is coming from several forms in a ASP.NET MVC application.
The report could have several layouts depending on the chosen template.
Your post to that software has given me the embryo of an idea of a possible improvement to the library. It can already export data to CSV and SQL, mainly for archiving purposes, but what about PDF (or HTML for that matter) for report generation?. I think it might be nice to be able to generate reports directly from a DB and squirt them out to, say, PDF.
how to generate and download pdf report from database in mvc using itextsharp c
Many of us tried to generate report in *.pdf format but there are no correct tools that just give this feature for free. Here I found one library iTextSharp.dll file which is for PDF reports but there are so many versions of it and it is really very hard to get the right DLL file to generate report, formatting, page numbers and all. So in this article, you will find all these things get done with a simple few lines of codes.
This project is done in ASP.NET using C# language. Here the database used is the Access database. But it really works with SQL Server too. I have tried SQL Server database too but it's easy for me to attach .mdb file in here. The article provides the easiest way to deal with multiple tables and retrieve data from multiple tables and generate the PDF file with header and footer. Also this article helps to insert the page number in each PDF page.
The whole project is attached in the zip file. You can just download and take benefit of this example in your project. The main gist code of the article is shown below. But before using this code, you have to add iTextSharp.dll version 4.1.2.0 file in the Reference of your project and on the top of the *.cs page, you have to import this file. The whole thing is shown in the downloadable zip file. I am getting data from multiple tables joining. The tables being used are CustomerOrder and OrderedItem which are shown in the codes below too. Using DataRelation feature for combining two tables with the total sum are automatically calculated and shown in the report. The codes for this are:
Recently I was looking for an Advance Tool to create complex PDF Report in C#.Netand I found iTextSharp. The main problem is that lacks of Documentation.Yes, there are a few examples in C#, but that is not sufficient to the Beginnersand the examples are in older version of iTextSharp, there are lotsof change in the latest version. So, it will be difficult for beginners to convertolder version to latest version. Besides, I think that if I write an Article onthis, then it will help me also as a future reference as I'll describe each functionalityof this library with example. Frankly speaking, in this Article, you find all theexamples from Chapter 1 of the book iText in Action, Second Edition which is written for Java Developers. I'llexplain all the examples of the rest Chapters in my next release of this Article.So if any one is interested in using this library, he/she will get a good kick start.
Whenever we add Layer in PDF Document, then the content of the Layer resides underOCG Group. So if I remove this Layer we can remove the content of theLayer also e.g. here it is Watermark Text. To remove all the Layers from PDF Document,you have to remove OCG Group completely from the Document using reader.Catalog.Remove(PdfName.OCPROPERTIES).Now follow the Steps below to remove the Watermark Text from Layer:
I've been trying to use iTextSharp to create a link to a page in another PDF document (see C# example at ) in an RS report that will be preserved when the report is exported to PDF. A programmer in our shop wrote a C# program to generate the entire PDF report with the links we want, but for obvious reasons, we'd prefer use RS to generate the report, and reference the itextsharp dll to embed the links.
Hello Everyone, In this article we are going to look into step by step approach to pull the content from SharePoint and put into a new PDF file using iTextSharp. Consider that we need to show the SharePoint List data in a PDF file.
Download the iTextSharp library from the link given above. In this article we are using iTextSharp-5.5.9 version. Add the dll into your solution to make use of the functionalities available in iTextSharp.
PDF documents are an essential part of many applications and websites. They are widely used for documentation, reports, invoices, etc. This article will show you how to create PDF documents using iTextSharp in a Blazor Server application.
iTextSharp is a free and open-source library for creating and manipulating PDF documents in .NET applications. It is a port of the iText library, a popular Java-based PDF library designed to provide similar functionality to .NET developers. iTextSharp allows you to create, read, and edit PDF documents and add text, images, and other elements to the document. It also supports advanced features such as encryption, digital signatures, and form filling. iTextSharp is widely used in .NET applications for generating PDF documents, such as reports, invoices, and other documents. It is a popular tool for developers because of its ease of use, flexibility, and ability to generate high-quality PDF documents with advanced features.
The first step is to install the iTextSharp library in your Blazor Server application. You can do this by using the NuGet Package Manager. Open Visual Studio and navigate to your project. Right-click on the project and select "Manage NuGet Packages". In the search box, type "iTextSharp" and select the iTextSharp package from the list. Click on "Install" to install the package.
Now that we have created a method to generate PDF documents, we can call this method from our Blazor Server application. In this example, we will add a button to our Blazor Server application to generate a PDF document when clicked.
TITextSharp is a powerful library that provides many advanced features for creating and manipulating PDF documents, and it is a great tool to have in your development toolbox. His article shows how to create a PDF document using iTextSharp in a Blazor Server application. We have created a simple PDF document with a title and some text, and we have added a button that generates the PDF document and a download link that allows the user to download the PDF document.
I've temporarily removed the hidden property so that I could troubleshoot and when the PDF form comes up I can see these fields have populated. However the custom calculation script does not seem to see these values as it only shows the 'hardcoded' text from the script. To simplify the script, I removed all fields to be concatenated except one. I then put a default value into the text field that would normally get its value from itextsharp. I then did a preview and the custom calculated field shows the text that I want it to with the default value from the text field. I am assuming this means the custom calculation javascript is written correctly.
I believe that my problem is that the custom calculation field is calculated BEFORE the text field is populated by itextsharp. I have tried moving the FirstParagraph field to the bottom using the "Set Field Calculation Order". However, since CustName receives its values from itextsharp and is not calculated it does not show up in this listing. I tried making CustName a calculated field by putting a custom calculation script in it. I then moved FirstParagraph field to be AFTER CustName in the order of calculation. still nothing appears except the 'hardcoded text'.
these forms will be used locally (on our network) by a group of individuals that need them auto populated from a web application that they will be using. Their machines are defaulted to open PDFs with Adobe Reader. The web application will be run from Chrome. The web application enables them to choose forms and data to be populated to the forms. the user then chooses a "Print" button which kicks off the code that runs the itextsharp and opens the chosen forms.
This article describes how to create a .Net Core 2.2 Console Application to create an PDF file using iTextSharp. The console application uses the iTextSharp package in the Repository to generate the Byte Stream and output SQL Server data into a PDF File. The Main section of the Console app will use Autofac to inject the Repository Class into the Service Class in the project and will be registered in a Container.
Create a stored procedure in SQL Server from the Adventure Works database using the View vVendorWithAddresses. This one provides a list of Vendors and Addresses for output into a list in a Mailing Address Label format in a PDF file.
Repository Class - Create a new Class that implements the Repository Interface with a generic Constructor and 3 variables for the SQL connection and the Stored Procedure name + the local Path to the newly created iTextSharp PDF file report. Implement the Repository Interface member WriteBytes which will generate the byte array for the report and pass a string with the Report Name of the new PDF file. Add 2 additional functions to Get the Data from the DataSet and to Get the PDF generated into a PDF report file using iTextSharp code.
An additional step to use a call System.Diagnostics.Process may be used to open the report after it has been created. The call does not work well when Debugging in Visual Studio as it appears to "Open" the file in a Hidden Acrobat application. When you attempt to open the .pdf file from its Saved location, a message tells you it is already open. When you force the Acrobat closed in Task Manager and open the PDF, a message informing you that the File is Corrupt appears.
This code calling Process.Start was added after debugging and opening the file from its Saved Location. To run the Published file, go to Run, type dotnet "C: " and the call to Process.Start will work as expected.
The Syncfusion Excel (XlsIO) library helps you to export data to Excel worksheets from databases like MS SQL, MS Access, Oracle, and more. By establishing a connection between the databases and Excel application, you can export data from a database to an Excel table.
35fe9a5643
Reply all
Reply to author
Forward
0 new messages