I need to generate PDF reports in a windows application I'm working on, and I do this by exporting an .xlsx file to pdf. I'm currently using interop for this, however:
Things I tried:
Help would be appreciated, thank you in advance :)
iTextSharp
I would use it except I need to export a big DataTable that has a variable number of columns (up to 30 columns), and if there are many columns then It gets really complicated to handle that column overflow, which was easy in interop.
Aspose
Appears to be too expensive, since I work for a small company that is currently very limited in resources.
Another good option is to use Spire.XLS. Though it will display evaluation warning at the top but you can get rid of it using FreeSpire.XLS. Below is the link for it https://www.nuget.org/packages/FreeSpire.XLS/
And below is the code snippet taken from
https://forums.asp.net/t/2087645.aspx?Saving+xlsx+to+pdf
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
namespace ConvertExcelToPdf
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\sample2.xlsx");
workbook.ConverterSetting.SheetFitToPage = true;
workbook.SaveToFile(@"..\..\sample.pdf", FileFormat.PDF);
System.Diagnostics.Process.Start(@"..\..\sample.pdf");
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With