Storing PDF document into stream is too slow in batch operation

Hi,


I want to produce payroll pdf document for all our employees. There is approximately 13000 employees in our company.

The code I used is similar with below:

License l = new License();
l.SetLicense(“Aspose.Total.lic”);

Document doc = new Document();

… The code which is drawing pdf content …

MemoryStream ms = new MemoryStream();
doc.Save(ms);

doc.Save(ms) method takes about 6-20 seconds in every iteration.

If I use aspose core font with table cells with like below:

TextState textState = new TextState(“Helvetica”);

doc.Save(ms) method takes about 4-15 seconds in every iteration.

If do not use TextState object in my table cells doc.Save(ms) method takes about 1-5 seconds in every iteration.

I can not understant the reason why It’s too slow like that.

I have to decrease these operation 0-1 seconds. Please give us a workaround for this issue.

Hi Mustafa,


Thanks for your inquiry. Usually performance depends upon the PDF document contents/size,operations and system resources. Can you please share some sample code snippet here? So will test the scenario at our end and will provide you more information accordingly.

We are sorry for the inconvenience faced.

Best Regards,

Hi,


I have shared our sample .net project with you. You can measure performance of pdf producing times with this .net project and than would you share your times in producing pdf?

Thank you.

Hi Mustafa,


Thanks for sharing the sample project.

I have tested the scenario and as per my observations, each page being added to PDF file takes around 12 - 14 seconds. Please note that instead of initializing the license on every loop iteration, I have moved the code from CreateWithDocument(…) method to Main(…) method. For
the sake of correction, I have logged this problem in our issue tracking system as
PDFNEWNET-35792. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We apologize for your inconvenience.

Console output

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:19.8808 Start: License

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:20.0156 End: License

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:20.0254 Start: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:20.0566 End: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:20.0625 Start: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:23.6775 End: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:23.6814 Start: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:23.7107 Start: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:25.8580 End: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:36.0448 End: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:36.0487 Start: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:36.0527 End: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:36.0546 Start: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:37.9939 End: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:37.9978 Start: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:38.0008 Start: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:38.0232 End: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:47.8400 End: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:47.8439 Start: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:47.8468 End: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:47.8497 Start: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:49.8125 End: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:49.8154 Start: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:49.8184 Start: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:30:49.8428 End: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:00.0042 End: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:00.0082 Start: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:00.0111 End: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:00.0169 Start: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:02.0305 End: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:02.0344 Start: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:02.0383 Start: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:02.0617 End: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:12.8179 End: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:12.8384 Start: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:12.8481 End: Page

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:12.8550 Start: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:15.1273 End: Table

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:15.1312 Start: Save

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:15.1351 Start: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 : 15:31:15.1595 End: Header/Footer

Aspose.Pdf.Test.vshost.exe Information: 0 :
15:31:26.0270 End: Save

Hello,


Any update in the issue. I have attached the following pdf that takes 37 seconds to save into the memory stream using the save function. Here is my code

public byte[] ConvertToSBytes(Aspose.Pdf.Generator.Pdf document)
{
byte[] PDfBytes;

#region “Convert the document into a Byte array”

using (MemoryStream memoryStream = new MemoryStream())
{
document.Save(memoryStream);
PDfBytes = memoryStream.ToArray();
}

#endregion

return PDfBytes;
}

Cody Maust:
Any update in the issue.
Hi Cody,

Thanks for contacting support.

Since the issue reported earlier was recently noticed, so the development team requires little time to investigate and figure out the reasons of this performance related issue.

Cody Maust:
I have attached the following pdf that takes 37 seconds to save into the memory stream using the save function. Here is my code

public byte[] ConvertToSBytes(Aspose.Pdf.Generator.Pdf document)
{
byte[] PDfBytes;

#region “Convert the document into a Byte array”

using (MemoryStream memoryStream = new MemoryStream())
{
document.Save(memoryStream);
PDfBytes = memoryStream.ToArray();
}

#endregion

return PDfBytes;
}
Now concerning to above stated issue, do you mean time is elapsed when loading the document into Byte array ? During my testing, I have used the following code snippet to load the document into Byte array using Aspose.Pdf for .NET 8.4.0 and as per my observations, the process completes in less than one second. I have tested the scenario over Windows 7 (X64), while using Visual Studio 2010 project on Intel Core i5 2.5 Ghz machine with 4 GB of RAM. Can you please share some details regarding your working environment. We are sorry for your inconvenience.

[C#]

Document document = new Document(“c:/pdftest/QuoteInformation.pdf”);<o:p></o:p>

byte[] PDfBytes;

#region "Convert the document into a Byte array"

using (MemoryStream memoryStream = new MemoryStream())

{

document.Save(memoryStream);

PDfBytes = memoryStream.ToArray();

}

#endregion

Console.WriteLine(PDfBytes.Length);

@SATINALMA

Thanks for your patience.

We have further investigated the earlier logged issue PDFNET-35792 and run some test with latest version Aspose.Pdf for .NET 17.11. We have found that performance with latest version was good, as scenario consumed about 2 seconds on first run, and less than 0.2 seconds on each repeating run.

(See: Console_out_17.png (95.9 KB)).

Please try using the latest release version and in case you face any issue, please feel free to contact.