First PDF Creation Everyday is Very Slow using Aspose.Words.DLL

Hi I am using Aspose.Words and document builder creating pdf from Sharepoint Infopath form using [Webmethod]. and setting licence like below

public string createPDF(int FormID, string PDFName)
{
Aspose.Words.License lic1 = new Aspose.Words.License();
lic1.SetLicense("…\License\Aspose.Total.lic");
}
However Issue here is everyday for first time pdf creation is taking bit more time than the subsequent PDF creation. Is there any workaround For this Issue?. any problem with “Aspose.Words.DLL” file ?,… why its happening everyday first pdf creation ?. Please note PDF file size is <40kb with less data.

Please help and share ur thoughts.

**Code Info : **
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.CellFormat.Borders.ClearFormatting();
** builder.Font.Size = 11;**
** builder.Font.Name = “Calibri (Body)”;**

** builder.InsertParagraph();**
** builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;**
** builder.InsertImage(image);**
** builder.Font.Bold = true;**
** builder.Write(" " + " " + “Test 123”+ " " + “”);**
** builder.Font.Bold = false;**
** builder.Write("\n");**
--------code goes like this----
-------
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);


** builder.PageSetup.PageStartingNumber = 1;**
** builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);**
** builder.Font.Size = 11;**
** builder.Font.Name = “Calibri (Body)”;**
** builder.Write(“Page “);**
** builder.InsertField(“PAGE”, “”);**
** builder.Write(” of “);**
** builder.InsertField(“NUMPAGES”, “”);**
** builder.Write(”\n”); **
** builder.Write(“test”);**
** builder.MoveToDocumentEnd();**

-----------code ends--------------------

** First PDF Creation Everyday is Very Slow using Aspose.Words.DLL. by using above code. Please help.**

@itsmedeepaku

Thanks for your inquiry. Please note on first call Aspose.Words needs to pre-cache fonts and other resources for rendering that takes some time. This only happens for the first conversion. As a work around you may call doc.UpdatePageLayout() on an empty document to pre-caching the related resources before converting Word to PDF. Hopefully it will help you to improve the performance.

However, if the issue persists then please share your sample console application along with input resource as ZIP file to replicate the issue at our end. We will look into it and will guide you accordingly.

Hi , Above Code is just part of the code. In Sharepoint Infopath form when we click on “Submit” button nintex workflow will run which calls a sharepoint webservice method. in that webmethod I have added “createpdf” method. that method get the data from infopath form and creates pdf using Aspose,words.DLL. issue is every day for the first submission , “createpdf” method is taking more time. suprisingly for the next infopath form submission. it is taking 5-6 seconds. I have enabled the custom logs in the code. here is the data for first record and subsequent record:

First record:
createPDF started 8/28/2017 6:00:48 AM
createPDF Ended 8/28/2017 6:01:16 AM
took 28 seconds
and now the second record log details.

createPDF started 8/28/2017 6:07:47 AM
createPDF Ended 8/28/2017 6:07:47 AM
same data not even 1 second to create pdf.

So every day for the first “PDF CREATION” why this behavior?

@itsmedeepaku

Thanks for your feedback. As stated above, first call is slow because Aspose.Words pre-cache the resources and fonts for subsequent use. In subsequent calls the required resources and fonts are already cached so it takes less time. Furthermore, your server would have been caching the resources on start and adding some time to first call as well. Please check following link hopefully it will help you to understand first call lag issue and it seems expected behavior.

P.S: Please follow your query in your other similar thread.

doc.UpdatePageLayout() do I need to add this as “First Line” in the code ?. Does this create an empty document ? or it will just initiate the resources(fonts etc). I don’t want to create empty document. because we are sending the pdf to another application(java based).

Thanks for your help.

@itsmedeepaku,

Thanks for your feedback. You can call UpdatePageLayout method on an empty document as following on Page load event to pre-cache fonts and other resources. There is no need to save document.

Document doc= new Document();
doc.UpdatePageLayout();

A post was split to a new topic: Only cache “common” fonts