Saving to PDF first time is slow

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,

This seems to be an expected behavior i.e. the first time after web server is restarted, rendering a Word document to PDF takes more time than any subsequent conversions. Aspose.Words needs to pre-cache fonts and other resources for rendering. This only happens for the first conversion. If you want to do this pre-caching earlier then you can simply call doc.UpdatePageLayout() on an empty document before converting Word to PDF.

However, executing your code with latest version of Aspose.Words for .NET 17.8 in a Console Application on our end (for the first time) took just 6473 milliseconds. So, please upgrade to the latest version and see how it goes on your end. Hope, this helps.

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"+ " " + "<PDF TITLE>");
       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--------------------
I am creating PDF using document builder .First PDF creation everyday taking long time. is there any bug in Aspose,Words.DLL ? Please help

@itsmedeepaku,

In case you observe the same problem with latest version of Aspose.Words for .NET i.e. 17.8, then please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end. Please ZIP and attach it here for testing. Thanks for your cooperation.

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
to**ok 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,

Please manually restart SharePoint services/servers, hit the ‘submit’ button two times and observe the difference between time taken by the first call and subsequent calls. I think, the problem occurs because the underlying services/server restart daily (check if you have any schedules defined). As stated before, Aspose.Words needs to pre-cache fonts and other resources for rendering. This only happens for the first conversion after web server is restarted.