What parameters do I have to prepare a PDF report from code in .NET for scientific data (winforms)

I have a β€œlegacy” VB.NET application (winforms) written for .NET 1.1 and recompiled in version 2.0, which generates a report in HTML using a special XmlTextWriter suitable for HTML. Then the user will print the report in pdf format if he wants.

It was 2003, and now the technology has changed a bit, especially in the C # / VB.NET world, and customers want to skip part of the HTML and go directly to PDF. What are my options for open source or low-cost PDF libraries that work well with .NET and should support image tables (generated bitmap images from code) and text.

Here is a screenshot of the resulting html rendering

HTML Report

Obviously, this needs some cleaning, cleaning, etc., but I'm interested in knowing which technology should be used in this project.

This related question may be what I need, or it may be out of date. I do not have data sources that provide all the information I want to display. It is currently being assembled from various classes in the application for display in html form.

Does anyone have direct experience with iTextSharp or SharpPDF ?

Thanks for any advice.

Update 1: found a possible duplicate here .

+4
source share
7 answers

Report.NET is a .NET PDF library designed to generate reports that supports the features you requested. It is smaller than iTextPdf, but perhaps sufficient for your needs:

http://sourceforge.net/projects/report/

(LGPL license).

+1
source

I used iTextSharp to create PDF reports before. Although you have to get used to the library (and this is an extensive library), once you master it, it is not so bad. I found the iText In Action book very useful. Although the book focuses on the Java source library, not the .NET port, most methods and classes are named the same, so there were no problems.

My # 1 tip when working with iTextSharp is that you will write a lot of the same code over and over again. (i.e. creating a table cell, setting fonts, sizes, colors and borders for this table cell, setting text ...). Do yourself a favor and create your own little Utility class that will do all your work, otherwise you will get 2,000 lines of code that simply create some tables with some special formatting.

There is also a series of short articles on this site that I found useful when I first studied iTextSharp.

Edit:

If you are interested in XHTML -> PDF Converter, I just found this blog post by Darin Dimitriov , which shows how to port the open-source Java library with flying saucers to .NET. He makes it look easy!

Interestingly, it seems that the flying saucer uses iText under the hood to perform the conversion.

+4
source

You can use this free print driver:

http://www.dopdf.com/

When you print on it, it produces a PDF.

+1
source

I studied this topic two months ago, and basically you have two ways:

Dlls

  • open source iTextSharp - well, don’t expect too much from it, it can generate PDF files from simple web pages, your spreadsheet seems pretty complicated, although some of them I don’t think you can do without it source code settings
  • paid options - I used ABCPdf, it works pretty smoothly, not everything is displayed as well as in the browser, but it does work, I think there are even more such libraries.

Command line tools

If you are fortunate enough to have full control of the server, I think this will be your best option.

I did not try to do two, though, I used hosting so that they were not an option for me

+1
source

I just wrote a TIP in CodeProject on how to do this without using any external dlls in a few lines.

Here is a short code copied:

 // ---------------------------------------------------------------------------------------------- // If you run this on Windows 10 (having it default printer "Microsoft Print to PDF" installed) // This should print a PDF file named "CreatedByCSharp.PDF" in your "MyDocuments" folder // containing the string "When nothing goes right, go left" // ---------------------------------------------------------------------------------------------- // If not present, you will need to add a reference to System.Drawing in your project References using System.Drawing; using System.Drawing.Printing; void PrintPDF() { // Set the output dir and file name string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string file = "CreatedByCSharp.pdf"; PrintDocument pDoc = new PrintDocument() { PrinterSettings = new PrinterSettings() { PrinterName = "Microsoft Print to PDF", PrintToFile = true, PrintFileName = System.IO.Path.Combine(directory, file), } }; pDoc.PrintPage += new PrintPageEventHandler(Print_Page); pDoc.Print(); } void Print_Page(object sender, PrintPageEventArgs e) { // Here you can play with the font style (and much much more, this is just an ultra-basic example) Font fnt = new Font("Courier New", 12); // Insert the desired text into the PDF file e.Graphics.DrawString("When nothing goes right, go left", fnt, System.Drawing.Brushes.Black, 0, 0); } 
+1
source

I ended up using iTextSharp to create image cards with some complicated formatting after being deeply disappointed with other libraries.

Where it really paid off, there was relevant documentation compared to other options. I believe that there is also the ability to automatically parse HTML / XML .

0
source

I also suggest taking a look at the PD4ML html in a PDF converting library . It has a fairly modest price for a paid product, but it supports many features and is instantly updated.

0
source

Source: https://habr.com/ru/post/1343495/


All Articles