0

I have a lot of tables with lot of rows and columns which I am trying to export into a pdf on a button click in an asp.net webform. This data looks good in a listview. I used iTextSharp, but I couldn't figure out how to export listview to pdf using iTextSharp. So I used datatable and it didn't look very well with iTextSharp. I came across "Spire.DataExport for .NET" but it doesn't seem to be available freely.

Please let me know what's the best way to export a listview into a pdf in asp.net.

UPDATE:

I tried using wkhtmltopdf from codaxy's github link. But even for a simple html line, the conversion is failing from the c# code. Any help on this will be really appreciated, as I have spent a lot of time on this getting nowhere.

c# code:

PdfConvert.ConvertHtmlToPdf( new PdfDocument { Html = "<html><h1>test</h1></html>" }, new PdfOutput { OutputFilePath = "inline.pdf" } );

Error::

Server Error in '/JobCosting' Application.

Html to PDF conversion of '-' failed. Wkhtmltopdf output:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: PdfConvertException: Html to PDF conversion of '-' failed. Wkhtmltopdf output:

Source Error:

Line 292: if (process.ExitCode != 0 && !File.Exists(outputPdfFilePath)) Line 293: { Line 294: throw new PdfConvertException(String.Format("Html to PDF conversion of '{0}' failed. Wkhtmltopdf output: \r\n{1}", document.Url, error)); Line 295: } Line 296: }

Rashmi Shivanna
  • 85
  • 2
  • 14

1 Answers1

0

Use wkhtmltopdf from https://wkhtmltopdf.org/ Make HTML from this list control using RenderControl method, and write it fo file, then run that wkhtmltopdf.exe from net using System.Diagnostics.Process class, then it produce pdf file

More answers here Convert HTML to PDF in .NET

codefox
  • 120
  • 8
  • I tried to implement what you said. But I am not sure what am doing wrong, I am not able to get it working. Please have a look at my post's update – Rashmi Shivanna Nov 25 '17 at 08:17