Aspose.Word printing is slow on first call on my colleague's PC

Hello,

On my pc, aspose.word is running quite smoothly, however on one of my colleague’s pc we can see a big difference when trying to print a file.

Indeed the creation steps last approximately the same but when printing, my computer needs less than two seconds to complete the task while it requires a good minute for my colleague’s.

However this difference occures only during the first print (we don’t see any major diffrence on the next ones).

Do you knwo why ?
Is it possible to speed up the print phase ?

Here are the specs for ou computers:
Mine PC1.png (3.4 KB)
my colleague’s PC2.png (4.9 KB)

Both are running a 64bits windows 10.

Sincerely.

@guyyyyyyyyyyy On the first call Aspose.Words inits static resources, such as fonts, which are then reused on the subsequent calls. The problems on your colleague’s machine might occur because there are much more fonts to read, that might take time.

You can create an empty document and save it as PDF, for example, on your application start to force Aspose.Words to init resources to avoid “cold” start on the real requests.

i tried to execute the following code only at the very first time my program uses aspose.word but the issue remains

public void InitOnce()
{
    var document = new Document();
    document.Save(_TempPath + "initFile.docm");
    File.Delete(_TempPath + "initFile.docm");
}

Was i supposed to use the same document object for the document i wanted to print ?

@guyyyyyyyyyyy You save the document as DOCM, this format does not require document rendering so Aspose.Words does not init the fonts. Please try saving as PDF as I have suggested earlier.
By the way, you can save the document into stream to avoid redundant file creation.

1 Like

This indeed helped a bit but the print process still requires 50 seconds whereas it took me 4 seconds.

Is there anything else i can do ?

@guyyyyyyyyyyy Unfortunately, it is difficult to say what the problem is. Does this occurs with some concrete document or with any document? Does the problem occur only while printing or it also occurs upon rendering document to PDF, for example? The problem might occur because some time is required to connect to the printer.

here is the concerned document but as said the issue seems to occur only on the first print
issue.docx (40.5 KB)

I will try to render a pdf document.

Is there a way to measure the time spent to connect to a printer ? In our case the printer used is pdf creator.

@guyyyyyyyyyyy Unfortunately, the problem is not reproducible on my side. It takes about 4 seconds to print the document on my side. Usually most of the time taken for printing is the time required to build document layout. You can measure this time by measuring time of the UpdatePageLayout method call:

Document doc = new Document("C:\\Temp\\in.docx");
// measure time of this method
doc.UpdatePageLayout();

doc.Print();

After building document layout is cached and reused upon printing. But since the problem occurs only on the firs call, it looks like some resources or connection initialization problem.

I tried to call the following code before printing instead of using UpdatePageLayout but the print still takes 40 seconds

using (MemoryStream ms = new MemoryStream())
{
    MyDocument.Save(ms, SaveFormat.Pdf);
 }

As suggested, i tried to render the document instead of printing and it works faster.
Does this mean the delay comes from the connection to the printer (even though the printer used is pdf creator) ?

@guyyyyyyyyyyy Yes, it looks like this is time required to connect to the printer. As I have mentioned usually the most time required for printing document is taken by building document layout. Since building document layout and rendering to PDF works fast on your side, we can make a conclusion the delay is causes by printer connection time.

1 Like