V10.1 long time to load

We’ve been using Aspose.Words version 8.1 and would like to now switch to the newer version, version 10. However on testing, when creating a new document, it takes much longer to load the document than the previous version. What can we do about that?

Hello Melissa,

In order to solve this problem, I need following details.

  1. Complete code snippet.
  2. Any source files.
  3. Time difference in document creation in previous and latest version.
  4. Hardware specifications.
  5. Software specification like OS Version.

I shall be able to go in depth of this problem after you provide me with the above details.

Code being used is below.
Old version took a couple of seconds. The new version took between 15-30 seconds.

OS = Windows XP

Microsoft Word V 2000 or 2003
It seems it’s only the first document that loads with the new version. Could this be? If yes, why?

public static bool loadDocument()
{
    string documentFilePath = "c:/documed/temp/123.doc"; 
    string jobName = ""; 
    string AmPm = ""; 
    string PtGender = ""; 
    int jobStatus = -1;
    String dateOfUpload = ""; 
    String timeOfUpload = "";
    DateTime dateofService = DateTime.Now; 
    string account = ""; 
    String dateofbirth = ""; 
    string firstname = ""; 
    string middlename = "";
    string lastname = "";
    string mrn = "";
    string room = "";
    string addrToLastName = "";
    string authorLastName = "";
    string authorInitials = "";
    string authorSignature = ""; 
    string addresseeSignature = ""; 
    string mtInitials = "";
    string site = "";
    string opt1 = "";
    string opt2 = ""; 
    string opt3 = ""; 
    string opt4 = ""; 
    string addressTo = ""; 
    string addressCC = "";

    // Set CustomDocumentProperties Using Aspose. Catch any errors with template
    // Load template; use Aspose to embed CustomDocumentProperties; Catch template errors
    try
    {
        Document doc = new Document(documentFilePath); // open document
                                                       // Create New Custom Document Properties if missing and fill
        if (doc.CustomDocumentProperties["~PtFirst"] == null)
            doc.CustomDocumentProperties.Add("~PtFirst", firstname);
        else
            doc.CustomDocumentProperties["~PtFirst"].Value = firstname;

        if (middlename.Length == 1) middlename += "."; // add period if only initial
        if (doc.CustomDocumentProperties["~PtMiddle"] == null)
            doc.CustomDocumentProperties.Add("~PtMiddle", middlename);
        else
            doc.CustomDocumentProperties["~PtMiddle"].Value = middlename;

        if (doc.CustomDocumentProperties["~PtLast"] == null)
            doc.CustomDocumentProperties.Add("~PtLast", lastname);
        else
            doc.CustomDocumentProperties["~PtLast"].Value = lastname;

        if (doc.CustomDocumentProperties["~AddresseeLast"] == null)
            doc.CustomDocumentProperties.Add("~AddresseeLast", addrToLastName);
        else
            doc.CustomDocumentProperties["~AddresseeLast"].Value = addrToLastName;

        if (doc.CustomDocumentProperties["~PtAcct"] == null)
            doc.CustomDocumentProperties.Add("~PtAcct", account);
        else
            doc.CustomDocumentProperties["~PtAcct"].Value = account;

        if (doc.CustomDocumentProperties["~PtDOB"] == null)
            doc.CustomDocumentProperties.Add("~PtDOB", "");
        else
            doc.CustomDocumentProperties["~PtDOB"].Value = dateofbirth;

        if (doc.CustomDocumentProperties["~PtGender"] == null)
            doc.CustomDocumentProperties.Add("~PtGender", PtGender);
        else
            doc.CustomDocumentProperties["~PtGender"].Value = PtGender;

        if (doc.CustomDocumentProperties["~PtMRN"] == null)
            doc.CustomDocumentProperties.Add("~PtMRN", mrn);
        else
            doc.CustomDocumentProperties["~PtMRN"].Value = mrn;

        if (doc.CustomDocumentProperties["~PtRoom"] == null)
            doc.CustomDocumentProperties.Add("~PtRoom", room);
        else
            doc.CustomDocumentProperties["~PtRoom"].Value = room;

        if (doc.CustomDocumentProperties["~DOS"] == null)
            doc.CustomDocumentProperties.Add("~DOS", dateofService);
        else
            doc.CustomDocumentProperties["~DOS"].Value = dateofService;

        if (doc.CustomDocumentProperties["~DD"] == null) // date dictated
            doc.CustomDocumentProperties.Add("~DD", dateOfUpload);
        else
            doc.CustomDocumentProperties["~DD"].Value = dateOfUpload;

        if (doc.CustomDocumentProperties["~DT"] == null) // date transcribed
            doc.CustomDocumentProperties.Add("~DT", DateTime.Today.AddHours(6));
        else
            doc.CustomDocumentProperties["~DT"].Value = DateTime.Today.AddHours(6);

        if (doc.CustomDocumentProperties["~DDTime"] == null)
            doc.CustomDocumentProperties.Add("~DDTime", timeOfUpload);
        else
            doc.CustomDocumentProperties["~DDTime"].Value = timeOfUpload;

        if (doc.CustomDocumentProperties["~AMPM"] == null)
            doc.CustomDocumentProperties.Add("~AMPM", AmPm);
        else
            doc.CustomDocumentProperties["~AMPM"].Value = AmPm;

        if (doc.CustomDocumentProperties["~AuthorInitials"] == null)
            doc.CustomDocumentProperties.Add("~AuthorInitials", authorInitials);
        else
            doc.CustomDocumentProperties["~AuthorInitials"].Value = authorInitials;

        if (doc.CustomDocumentProperties["~AuthorSignature"] == null)
            doc.CustomDocumentProperties.Add("~AuthorSignature", authorSignature);
        else
            doc.CustomDocumentProperties["~AuthorSignature"].Value = authorSignature;

        if (doc.CustomDocumentProperties["~AddresseeSignature"] == null)
            doc.CustomDocumentProperties.Add("~AddresseeSignature", addresseeSignature);
        else
            doc.CustomDocumentProperties["~AddresseeSignature"].Value = addresseeSignature;

        if (doc.CustomDocumentProperties["~AuthorLast"] == null)
            doc.CustomDocumentProperties.Add("~AuthorLast", authorLastName);
        else
            doc.CustomDocumentProperties["~AuthorLast"].Value = authorLastName;

        if (doc.CustomDocumentProperties["~AudioNo"] == null)
            doc.CustomDocumentProperties.Add("~AudioNo", jobName);
        else
            doc.CustomDocumentProperties["~AudioNo"].Value = jobName;

        if (doc.CustomDocumentProperties["~mtInitials"] == null)
            doc.CustomDocumentProperties.Add("~mtInitials", mtInitials);
        else
            doc.CustomDocumentProperties["~mtInitials"].Value = mtInitials;

        if (doc.CustomDocumentProperties["~Site"] == null)
            doc.CustomDocumentProperties.Add("~Site", site);
        else
            doc.CustomDocumentProperties["~Site"].Value = site;

        if (doc.CustomDocumentProperties["~V_01"] == null)
            doc.CustomDocumentProperties.Add("~V_01", opt1);
        else
            doc.CustomDocumentProperties["~V_01"].Value = opt1;

        if (doc.CustomDocumentProperties["~V_02"] == null)
            doc.CustomDocumentProperties.Add("~V_02", opt2);
        else
            doc.CustomDocumentProperties["~V_02"].Value = opt2;

        if (doc.CustomDocumentProperties["~V_03"] == null)
            doc.CustomDocumentProperties.Add("~V_03", opt3);
        else
            doc.CustomDocumentProperties["~V_03"].Value = opt3;

        if (doc.CustomDocumentProperties["~V_04"] == null)
            doc.CustomDocumentProperties.Add("~V_04", opt4);
        else
            doc.CustomDocumentProperties["~V_04"].Value = opt4;

        if (doc.CustomDocumentProperties["~IsNew"] == null)
            doc.CustomDocumentProperties.Add("~IsNew", true);
        else
            doc.CustomDocumentProperties["~IsNew"].Value = true;

        // Set Word Builtin Document Properties
        doc.BuiltInDocumentProperties.RevisionNumber = 0;
        doc.BuiltInDocumentProperties.CreatedTime = DateTime.Now;
        doc.BuiltInDocumentProperties.TotalEditingTime = 0;
        doc.Range.UpdateFields();

        // Insert address info to Bookmarks Using Aspose
        Bookmark bookmark1 = doc.Range.Bookmarks["Addressee"];
        if (bookmark1 != null)
            bookmark1.Text = addressTo;

        Bookmark bookmark2 = doc.Range.Bookmarks["CC"];
        DocumentBuilder builder = new DocumentBuilder(doc);

        if (addressCC == "")
        {
            if (bookmark2 != null)
                bookmark2.Text = "";
        }
        else
        {
            if (bookmark2 == null)
            {
                builder.MoveToDocumentEnd();
                builder.Writeln();
                builder.StartBookmark("CC");
                builder.EndBookmark("CC");
                bookmark2 = doc.Range.Bookmarks["CC"];
            }

            // if (Program.prefDocumentCCPrefix == "True")
            addressCC = "CC:\t" + addressCC.Replace("\r\n", "\r\n\t"); // add tab characters
            bookmark2.Text = addressCC;
        }

        // Use Aspose to save template with new file name
        doc.Save("C:/DocuMed/temp/abc.doc", SaveFormat.Doc);
        return true;
    }
    catch
    {
        // Display a bad template message.
        DialogResult res = MessageBox.Show("Problem with Document or Template selected.", "Open Document",
    MessageBoxButtons.OK,
    MessageBoxIcon.Error);
        return false;
    }
    return true;
}

Hi
Thanks for your request. The difference occurs in UpdateField method. In older versions of Aspose.Words this method does not call UpdatePageLayout method. But in the newer versions when you call UpdateFields method, it internally calls UpdatePageLayout to build page layout. This is needed to update fields that use page numbers (TOC for example). Updating page layout is quite time and memory consuming operation. That is why updating fields in newer versions is a little slower. However, the benefit is that you no longer need to call UpdatePageLayout separately.
Best regards,

It seems like it’s only the first document that we open after switching to the new version, not every document. Does anything happen with Aspose on the first time it opens(ex: load into memory, register on the computer, etc.), that could be causing this?

Hi
Thanks for your request. Upon the first time, Aspose.Words initializes common static resources, for example fonts installed on the PC. This could make a difference.
Best regards,

Is there any way we can avoid this or tell it to initialize as soon as they load the program instead of when opening the first document? Or should we rather use a different version (if yes, then which one)?

Also, how long should the update take in normal circumstances? It seems to be taking > 15 seconds which is unacceptable. Can something be done in the next update to reduce this?

Hello
Thanks for your request. Aspose.Words renders about 10 pages per second. So you can approximately calculate how much time it will take to render/update your document.
Also, there is no way to avoid this behavior.
Best regards,

Hi Melissa,

I believe you can tell Aspose.Words to initialize at start up by using the following code:

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

Please let us know if we can help with anything else.

Thanks,