Save document as PDF hangs

We have an issue with one document (attached) which hangs indefinately.
From a thread dump, I can see it is stuck on a socket connectFrom a thread dump, where it appears to be trying to load an image, but the site is unreachable

java.lang.Thread.State: RUNNABLE at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) - locked <4f07b1ed> (a java.net.SocksSocketImpl) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570) at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141) at sun.net.NetworkClient.doConnect(NetworkClient.java:163) at sun.net.www.http.HttpClient.openServer(HttpClient.java:411) at sun.net.www.http.HttpClient.openServer(HttpClient.java:525) - locked <43e3425e> (a sun.net.www.protocol.https.HttpsClient) at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:272) at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:923) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133) at asposewobfuscated.MH.Zj(Unknown Source) at com.aspose.words.JF.Ã(Unknown Source) at com.aspose.words.JH.hb(Unknown Source) at com.aspose.words.JH.h9(Unknown Source) at com.aspose.words.JH.toByteArray(Unknown Source) at com.aspose.words.ImageData.toByteArray(Unknown Source) at com.aspose.words.ZRH.Z(Unknown Source) at com.aspose.words.ZRJ.Ã(Unknown Source) at com.aspose.words.ZRJ.Ã(Unknown Source)

I tested this with the latest 13.5 release, but it does not work.We converts thousands of documents to PDF and so far this is the only one we have found with this kind of error.
The source is basically

Document doc = new Document(byteInputStream);
SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.PDF);
doc.save(byteOutputStream, saveOptions);

Is there a way to configure Aspose.Words to not load in anything from an external site?
Or is there a fix available for this issue?
thanks, Andy Rogers

Hi Andy,

Thanks for your inquiry. In your case, I suggest you please use the LoadOptions.setPreserveIncludePictureField(true) method to preserve the INCLUDEPICTURE field when reading Microsoft Word formats. The default value is false. Hope this helps you. Please let us know if you have any more queries.

LoadOptions lo = new LoadOptions();
lo.setPreserveIncludePictureField(true);
Document doc = new Document(MyDir + "Report+Results.doc", lo);
doc.save(MyDir + "out.pdf");

Hi,
After upgrading to a more recent release, loadOptions.setPreservedIncludePictureField(true); worked just fine, but it’s not clear what this method does. I could not find any documentation on this.
I also found the following worked.

loadOptions.setResourceLoadingCallback(new MyResourceCallBack());

class MyResourceCallBack implements IResourceLoadingCallback
{
    @Override
    public int resourceLoading(ResourceLoadingArgs arg0)
    {
        arg0.setData(null);
        arg0.setUri(null);
        return -1;
    }
}

Thanks, Andy

Hi Andy,

Thanks for your inquiry. Unfortunately, LoadOptions.setPreserveIncludePictureField is missing in Aspose.Words for Java documentation. Please accept my apologies for your inconvenience.

Your document contains the INCLUDEPICTURE fields. Yes, the reported issue can also be solved by IResourceLoadingCallback interface.

LoadOptions.setPreserveIncludePictureField sets whether to preserve the INCLUDEPICTURE field when reading Microsoft Word formats. The default value is false. By default, the INCLUDEPICTURE field is converted into a shape object. You can override that if you need the field to be preserved, for example, if you wish to update it programmatically. Note however that this approach is not common for Aspose.Words. Use it on your own risk.

One of the possible use cases may be using a MERGEFIELD as a child field to dynamically change the source path of the picture. In this case you need the INCLUDEPICTURE to be preserved in the model.

I have just downloaded the latest Aspose.Words 13.12.0 release, to see if another defect was fixed, and found this issue is happening again.
Any ideas?

Hi Andy,

Thanks for your inquiry. I have tested the scenario with shared document (in your first post) and have not found any issue while exporting document to Pdf. I have attached the output Pdf file with this post for your kind reference.

If you are facing some different issue, please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please create a standalone/runnable simple application that demonstrates the issue which you are facing.

As soon as you get these pieces of information to us we’ll start our investigation into your issue.