CommonUtilities is a custom class. Please download or clone this updated example project and let us know if you face any issue. You can further explore this developer guide.
Hi Atir_Tahir,
Thanks for your reply.
We are evaluating PDF tools for generating PDF reports with 10000 lines quickly. We tried your Aspose.Cells. It took about 8s. We’s like to achieve it within 2s. I should be grateful if you can shed light. An example code would be appreciated. Please see my test code using Aspose below. I wonder GraphDocs may be an option.
private static void ExportToPdfFromJson(List<HistoryLogReportRow> report)
{
var startTime = DateTime.Now;
// create a Workbook object
var workbook = new Workbook();
// access default worksheet
var worksheet = workbook.Worksheets[0];
// read JSON data from file
string jsonInput = JsonSerializer.Serialize<List<HistoryLogReportRow>>(report);
// set JsonLayoutOptions to treat Arrays as Table
var options = new JsonLayoutOptions();
options.ArrayAsTable = true;
// Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = worksheet.PageSetup;
// Setting worksheet name at the left section of the header
pageSetup.SetHeader(0, "&\"Times New Roman,Bold\"&20 WMS+ History Report");
// Setting current date and current time at the right section of the header
// and changing the font of the header
pageSetup.SetHeader(2, "&D-&T");
// Setting current file name at the right section of the header and changing the
// font of the header
//pageSetup.SetHeader(2, "&\"Times New Roman,Bold\"&12&F");
// Setting a string at the left section of the footer and changing the font
// of a part of this string ("Carrier")
pageSetup.SetFooter(0, "&\"Courier New\"&14 Carrier");
// Setting the current page number at the central section of the footer
//pageSetup.SetFooter(1, "&P");
// Setting page count at the right section of footer
pageSetup.SetFooter(2, "Page &P of &N");
// import JSON data to worksheet starting at cell A1
JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);
//worksheet.AutoFitColumns();
worksheet.Cells.SetColumnWidth(0, 20);
worksheet.Cells.SetColumnWidth(1, 20);
worksheet.Cells.SetColumnWidth(2, 80);
worksheet.Cells.SetColumnWidth(3, 20);
worksheet.Cells.SetColumnWidth(4, 20);
foreach (Worksheet item in workbook.Worksheets)
{
item.PageSetup.Orientation = PageOrientationType.Landscape;
}
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.AllColumnsInOnePagePerSheet = true;
// convert imported JSON to PDF
workbook.Save("historyReport.pdf", pdfSaveOptions);
// convert imported JSON to PDF
//workbook.Save("historyReport.pdf", SaveFormat.Auto);
var elapsedTime = DateTime.Now.Subtract(startTime).TotalMilliseconds;
}
It depends upon the number of columns also. But, I think it is reasonable time if it has complex data with more columns list. By the way, did you check which of the following line of code is taking more time to process:
pdfSaveOptions.AllColumnsInOnePagePerSheet = true;
(Please note this line might take more time if there is long list of columns to be pasted on page)
Anyways, if you still think it is an issue regarding performance, kindly do share a sample a standalone VS.NET console application with JSON data (file) to reproduce the issue on our end. We will check it soon.
PS. please zip the project with resource files prior attaching here (please exclude Aspose.Cells.Dll to minimize the size)
@Amjad_Sahi Thanks. The number of columns of the sample data is just 5. The data are very simple. Please see the attachment. The two methods you mentioned don’t take much time (within 123 ms or may be as low as a couple of ms). JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);
workbook.Save(“historyReport.pdf”, pdfSaveOptions); took most of the time. Changing pdfSaveOptions to SaveFormat.Auto from pdfSaveOptions.AllColumnsInOnePagePerSheet = true seems having no difference. Please shed light.
Please find Aspose ExportToPdfFromJson data and source.zip: https://drive.google.com/file/d/1xgBTvsdpPNXXrFRYSCru6ZJtY6UWqomV/view?usp=sharing
This is good news. Can you please send me Aspose.Cells for .NET 5.0 v21.10.1?
I’ve tried the component for .NET 4.0 in my .NET 5.0 project, I got the following error:
Could not load file or assembly ‘Aspose.Cells, Version=21.10.1.0, Culture=neutral, PublicKeyToken=716fcc553a201e56’. The system cannot find the file specified.
Hi Amjad, Yes, new Aspose cells is very good. Another question: if our PDF format is just simple reports, will Aspose cells be enough? Do we need to use Aspose.Pdf? I think groupdocs is also your product. Which product offers the best performance (fastest pdf generation), Aspose cells, Aspose.Pdf or groupdocs? Thanks for your support.
Sorry I gave you a json data file with fewer than 10000 lines. The total PDF generation and saving time would be 4.5s for the attached json data file with 10000 lines. Is there any room for improvement? It seems the real issue is the number of the lines of the data source rather than the version of Aspose Cells.
We will publish our next official release (Aspose.Cells for .NET v21.11) in Downloads/Nuget repos. around the mid of November, 2021, so you may get the .NET5.0 Dll from the release.
Yes, it will be enough. If you need to manipulate PDF files then you may consider using Aspose.PDF.
4.5s, I guess, this is reasonable time. Also, we could not find your JSON file data, you probably forgot to attach the attachment or there is something wrong with the archive.
@Amjad_Sahi Thanks for your reply. The json file I sent to you bounced back because it’s not the supported file format for this forum. Then I sent you a zip file through my email client. Maybe that’s not the way to share the file in this forum. Here is the link to the file https://drive.google.com/file/d/1QUgrg2QOq4PIS79bAABjXxgb6XuJePXy/view?usp=sharing
Can you please give another try?
Please share some tips on how to make the PDF file saving faster.
I think groupdocs is also your product. Do you think groupdocs can be faster? Do you recommend us to try it?
I tried your new JSON file and it takes a few seconds (8-10) to complete the process on my end. I guess it is reasonable considering the 10000 or more records. We might not improve on it.
You can try it if it works in lessor time. By the way, Aspose APIs are also used in GroupDocs in the backend.