问题
Iam using ASP.Net along with iTextsharp to generate PDF files. Data is returned from SQL Server in to ASP.Net in the form of a DataTable. For example if my datatable contains 1000 records with varying company id and branch id, my requirement is to write PDFs grouped by companyid and branch id.
CompanyID Code Name BranchId Amount
1 XXXX xxx 10 XXXX
1 XXXX xxx 20 XXXX
5 XXXX xxx 20 XXXX
1 XXXX xxx 10 XXXX
1 XXXX xxx 10 XXXX
2 XXXX xxx 30 XXXX
5 XXXX xxx 30 XXXX
3 XXXX xxx 20 XXXX
1 XXXX xxx 50 XXXX
4 XXXX xxx 20 XXXX
6 XXXX xxx 20 XXXX
4 XXXX xxx 10 XXXX
My main problem is that its taking too much time to generate PDFs. My logic is simple:
foreach companyId in distinct Companylist
foreach branchid in companyId
Populate data based on a HTML template
Write the HTML output to PDF using iTextsharp
loop
loop
Is there any better approach? For 200 records, it took 30minutes to generate the PDFs. How do I minimize the time. Please help.
来源:https://stackoverflow.com/questions/38739843/pdf-creation-using-itextsharp-taking-too-much-of-time