I noticed that Aspose.Words tries to resolve remove resources when creates a PDF.
I create a Word document. Then I go to Insert -> Quick Parts -> Field and I select IncludePicture. I add a URL to a remote image and I select “Data not stored with document” option. I save the document and then I user Aspose.Words to create a PDF. In order to create the PDF, Aspose.Words fetches the remote image.
Is there any option to prevent Aspose.Word to fetch remote resources when creating a PDF?
Thanks for your inquiry. Yes, you can achieve your requirement by implementing IResourceLoadingCallback interface. Please implement this interface if you want to control how Aspose.Words loads external resource when importing a document from HTML or MHTML.
Please use the following code example to get the desired output.
Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.ResourceLoadingCallback = new HandleResourceLoading();
Document doc = new Document(MyDir + "in.docx", loadOptions);
doc.Save(MyDir + "19.2.pdf");
public class HandleResourceLoading : IResourceLoadingCallback
{
public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
{
String url = args.OriginalUri;
if (args.ResourceType == ResourceType.Image || url.Contains("http://"))
return ResourceLoadingAction.Skip;
return ResourceLoadingAction.Default;
}
}