We are moving away from SautinSoft to using Aspose.Words .Net.
We have noticed how when SautinSoft renders a PDF from html it does a preprocessing step where it will resize images to stop an image from adjusting expanding or wrapping the html.
We do not like this as a practice BUT it has caused us a problem - We do know how often this has happened with our existing data. We have LOTS of historic data, far far to much to check.
Is there additional code that can added to an Aspose Word.net implementation that will implement this SautinSoft feature?
This kind of thing we see is shown below:
I am already adding code to capture when rendering an image fails using a CustomResourceLoadingCallback.
(See below)
Is there a way of implementing a similar feature to handle the image resize problem?
I do not want to simply resize all images on a ResourceLoadingAction
ResourceLoading
call as I do not know whether a size is necessary and I have no context to tell me when it is necessary.
// Within the rendering method:
LoadOptions loadOptions = new LoadOptions
{
LoadFormat = loadFormat,
ResourceLoadingCallback = new CustomResourceLoadingCallback() // Register / implement this call back to see where handling individual resources like images can raise errors
};
Document doc = new Document(inputStream, loadOptions);
// Now the CustomResourceLoadingCallback class
using Aspose.Words.Loading;
using System;
namespace XXXX
{
internal class CustomResourceLoadingCallback : IResourceLoadingCallback
{
/// <summary>
/// ResourceLoading
/// This method is called when Aspose.Words needs to load a resource, such as an image.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
{
if (args.ResourceType == ResourceType.Image)
{
try
{
using (WebClient client = new WebClient())
{
System.Diagnostics.Debug.WriteLine(String.Format("{0} {1}", ServicePointManager.SecurityProtocol, args.Uri));
Byte[] imageData = client.DownloadData(args.Uri);
args.SetData(imageData);
return ResourceLoadingAction.UserProvided;
}
}
catch (Exception Ex)
{
// Report when and why image loading failed
String errorMessage = String.Format("Failed to load image from {0}\nMessage: {1}\nStackTrace: {2}", args.Uri, Ex.Message, Ex.StackTrace);
System.Diagnostics.Debug.WriteLine(errorMessage);
AsposePDFHandler.Logger.LogError(errorMessage, Ex);
args.SetData(null);
}
}
return ResourceLoadingAction.Default;
}
}
}
Thanks