Performance issue converting word to JPEG

Im in the processes of evaluating Aspose to be used in the product.

Trying to convert a 53 kb 6 pages Microsoft word file and have some performance concern.

adding the code snippet used to do the save and the time take to convert each step

doc = new Document(sourceFilePath);
// took 54299 milliseconds for the above action

ImageSaveOptions options =
new ImageSaveOptions(com.aspose.words.SaveFormat.JPEG);
options.setPageIndex(pageNumberInsideFile - 1);
options.setPageCount(1);
type =
StringUtilities.getEnumFromValue(ImageType.class, format, ImageType.JPEG);
//to get a unique file name to store the converted page
tempFileName = getTemporalFileName(type);

doc.save(tempFileName, options);
// took 59299 milliseconds to save
resultFile = new File(tempFileName);

Overall it took 1.7 mins

Is there any option to speed this process ?




Hi there,

Thanks for your inquiry. It is quite difficult to answer such
questions because CPU performance and memory usage all depend on
complexity and size of the documents you are loading/generating.


In
terms of memory, Aspose.Words does not have any limitations. If you’re
loading huge Word documents into Aspose.Words’ DOM, more memory would be
required. This is because during processing, the document needs to be
held wholly in memory.

While rendering a document to fixed page formats (e.g. PDF, Jpeg, Xps), Aspose.Words needs to build two model in the memory – one for document and the other for rendered document.

The process of building layout model is
not linear; it may take a minute to render one page and may take a few
seconds to render 100 pages. Also, Aspose.Words has to create APS (Aspose Page Specification)
model in memory and this may again eat some more time for some
documents. Rest assured, we’re always working on improving performance;
but, rendering will be always running slower than simple saving to flow
formats (e.g doc/docx).

Hi Tahir,


Thanks for you reply. I ran the same file thru the demo code in the site and I see it vast difference in the time. Its faster in the demo code, do we need to initialize anything when the server starts up ?
Thanks

Hi there,

Thanks for your inquiry. There is nothing to initialize at server.
Perhaps, at your server the fonts are missing which may take some time
for font substitution.

Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats (JPEG, PDF or XPS). Make sure you have all the Fonts installed on your machine you’re using to convert Word document to Jpeg format. I would suggest you please read the
following article:
http://www.aspose.com/docs/display/wordsjava/How+Aspose.Words+Uses+True+Type+Fonts

Please read about system requirements from here:
http://www.aspose.com/docs/display/wordsjava/System+Requirements

Hi,

I tried to add callback to handleDocumentWarning using an example i found on the site and I did not find any fonts missing.
Any other suggestions to improve the performance of the initial loading.

HandleDocumentWarnings callback = new HandleDocumentWarnings();
ImageSaveOptions options = new ImageSaveOptions(com.aspose.words.SaveFormat.JPEG);
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();

options.setPageIndex(pageNumberInsideFile - 1);
options.setPageCount(1);
options.setWarningCallback(callback);


—
public class HandleDocumentWarnings implements IWarningCallback {
/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory.getLogger(HandleDocumentWarnings.class);

/**
* Our callback only needs to implement the “Warning” method. This method is called whenever there is a potential issue during document procssing. The
* callback can be set to listen for warnings generated during document load and/or document save.
*/
public void warning(WarningInfo info) {
// We are only interested in fonts being substituted.
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION) {
 
LOGGER.info("Font substitution: " + info.getDescription());
}
}
}

Hi there,

Thanks for your inquiry. When a document is loaded into Aspose.Words DOM, it takes some time to load all resources first time, for example fonts installed on the PC. Please note that usually Aspose.Words needs few times more memory than document size to build model of the document (DOM) in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

It
is quite difficult to answer such questions because CPU performance and
memory usage all depend on complexity and size of the documents you are
loading/generating.

Hope this answers your query. Please let us know if you have any more queries.

Hi Tahir,
Thanks for the explanation .The point I am trying to make is when i run the same file thru your demo on the same box I get much faster results than on my server (Tomcat 8, Java 8). That is the difference I am trying to figure out.

I am attaching a file can you tell me how long it took in your end to open it convert it to JPEG and save it in the filesystem please.

Hi there,

Thanks for sharing the detail.

I have executed the shared code at Tomcat 8, Java 8, Windows 7 (64 bit), 8 GB Ram. Following are the results at my end.

Execution time, first time: 1280 ms
Execution time, second time : 312 ms
Execution time, third time : 196 ms
Execution time, fourth time : 168 ms

I have created a Java code example which load and save the document twice at Windows 7 (64 bit), 8 GB Ram and Java 8. Following are the results at my end.

Execution time, first time : 1743 ms
Execution time, second time : 282 ms

In both cases, the results are approximately same. Please test the same scenario at some different systems (using Tomcat and simple Java application).
danros:

The point I am trying to make is when i run the same file thru your demo on the same box I get much faster results than on my server (Tomcat 8, Java 8).

I suggest you please create a separate simple Java application to test this scenario. If you have any other jar files, please remove these jar files and check this scenario again. You may share these jar files with us for further testings. Please let us know if you have any more queries.

Hi Thanks for the response.

We were using Tomcat 8.0.14 and saw the perfomance issues. I tried it with 8.0.23 and see it down to 8.382. Can you please tell me what tomcat 8 version did you use and if you have to make any configuration changes to it please.

Hi there,

Thanks for your inquiry. I used the apache-tomcat-8.0.23 for testing. I have not set any configuration at my side. I used apache-tomcat-8.0.23 with default configuration. I will test the same scenario using apache-tomcat-8.0.14 at my side and share my findings here for your reference.

Hi,

On Tomcat 8.0.23 I see <span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Execution time: 5130
milliseconds.
Is it possible to zip up your tomcat and code , I can compare and see how its different from mine.
Thanks

Hi there,

Thanks for your inquiry. I have tested the same scenario using apache-tomcat-8.0.14, Java 8, Windows 7 (64 bit), 8 GB Ram. Following are the results at my end.

Execution time, first time: 14147 ms
Execution time, second time : 268 ms
Execution time, third time : 198 ms

It seems that the issue is with older version of apache-tomcat-8.0.14. The same version of Aspose.Words for Java 15.4.0 works good at apache-tomcat-8.0.23.

danros:

On Tomcat 8.0.23 I see Execution time: 5130 milliseconds. Is it possible to zip up your tomcat and code , I can compare and see how its different from mine.

I have attached the code example (.jsp file) with this post for your kind reference. Please download apache-tomcat-8.0.23 from here:
https://tomcat.apache.org/download-80.cgi

Please let us know if you have any more queries.