We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Loading External resources

Hi Team,

We are using following code to load/skip the external resources:

public Aspose.Words.Loading.ResourceLoadingAction ResourceLoading(Aspose.Words.Loading.ResourceLoadingArgs args)
		{
			
			if ((data.LoadExternalResources == false) &&  ((IsValidUrl(args.Uri)) || (IsValidUrl(args.OriginalUri))))
			{
				log.Info("Found externally linked resources.. Skipping the loading of the resources");
				return Aspose.Words.Loading.ResourceLoadingAction.Skip;
			}
			else
			{
				log.Info("Loading the resources..");
                try
                {
                    //Bug 1660983: Workaround code suggested by Aspose in Ticket#175381.
                    //This code can be removed after a fix is delivered by Aspose.
                    var uri = args.OriginalUri;
                    HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
                    webRequest.UserAgent = "";
                    webRequest.Accept = "*/*";
                    webRequest.AutomaticDecompression = DecompressionMethods.GZip;
                    webRequest.AllowAutoRedirect = true;
                    WebResponse webResponse = webRequest.GetResponse();
                    Stream stream = webResponse.GetResponseStream();
                    var ms = new MemoryStream();
                    stream.CopyTo(ms);
                    args.SetData(ms.ToArray());
                    return Aspose.Words.Loading.ResourceLoadingAction.UserProvided;
                }
                catch (Exception e)
                {
                    log.Error("Loading of the resource " + args.OriginalUri + " failed with exception " + e);
                    return Aspose.Words.Loading.ResourceLoadingAction.Skip;
                }
            }
		}
	}

If it does not load or skip the external resources ,it replaced with ‘Red X’ image.
I have attached two files email with initial inline image and pdf file after loading external resources.
Please let us know to meet the following requirements:
The size of ‘Red X’ image should be small like 2cm x 2cm instead of size of original image.
Have a hover capability/ hyperlink on the ‘Red X’ or text added to the ‘Red x’ box with the URL of the image location.

Please suggest code snippets for this requirement?

Thanks,
KavithaTest1.zip (91.3 KB)

@Kofax_Business_Communications

Could you please attach the following resources here for testing:

  • Your input HTML document.
  • Please attach the expected output PDF file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi Team,

We are using attached program.cs file to skip the external load resources.
Please find the attached input file as unknown.html and current behaviour of outputfile as unknown_withoutload_resources.pdf.
when skip the load resources, we need a small X with the rest of the space being white (with a faint grey border) to cover the area of the original image.
We need output of resouce like Red_X.png instead of big Red X.

Test.zip (426.7 KB)

Thanks,
Kavitha

@Kofax_Business_Communications

We have logged a feature request as WORDSNET-22929 to achieve this requirement. We will inform you via this forum thread once this feature is available. We apologize for your inconvenience.

Hi Team,

Thanks for sharing information.
Please include following information in feature request WORDSNET-22929 :
when skip the load resources, we need a small X with the rest of the space being white (with a faint grey border) to cover the area of the original image.
We need output of resource like Red_X.png instead of big Red X.

Please let us know ETA for this FR?

Test.zip (426.7 KB)

Thanks,
Kavitha

@Kofax_Business_Communications

Aspose.Words does not generate such images. You need to add your own image with skipped images.

Could you please ZIP and attach the expected output PDF here for our reference?

Hi Team,

when skip the load resources, we need a small X with the rest of the space being white (with a faint grey border) to cover the area of the original image.
We need output of resource like Red_X.png instead of big Red X.
Please find the attached input file unknown.html and output file unknown_withoutload_resources_userprovided.pdf file, Red_X.png for your reference. The red x should be small and rest of the space being white (with a faint grey border) to cover the area of the original image.

Test.zip (553.5 KB)

Thanks,
Kavitha

@Kofax_Business_Communications

Thanks for sharing the detail. We have logged it in our issue tracking system. We will check the possibility of implementation of this feature and inform you via this forum thread once there is any news available on it.

Hi Team,

Please let us know ETA for this issue.

Thanks,
Kavitha

@Kofax_Business_Communications

We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies

Hi Team,

Please let me know update on this issue?

Thanks,
Kavitha

@Kofax_Business_Communications The issue is currently in the que for analysis. We will keep you informed and let you know once there is any update.

Hi Team,

Please let me know update on this issue?

Thanks,
Kavitha

@Kofax_Business_Communications Unfortunately, there is still no news regarding this features.

Hi Team,

Please let me know any update on this issue?

Thanks,
Kavitha

@Kofax_Business_Communications We completed analyzing the issue and are going to close it as Won't Fix, because you can use existing Aspose.Words API to identify images where resource loading was skipped and set a custom image for it. For example see the following code:

LoadOptions opt = new LoadOptions();
opt.ResourceLoadingCallback = new ResourceLoadingCallback();
Document doc = new Document(@"C:\Temp\unknown.html", opt);

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape s in shapes)
{
    if (s.ImageData.IsLinkOnly)
    {
        // Here you can set a custom image for a skipped resource.
        s.ImageData.ImageBytes = File.ReadAllBytes(@"C:\Temp\image1.png");
    }
}

doc.Save(@"C:\Temp\out.pdf");
private class ResourceLoadingCallback : IResourceLoadingCallback
{
    public Aspose.Words.Loading.ResourceLoadingAction ResourceLoading(Aspose.Words.Loading.ResourceLoadingArgs args)
    {
        return Aspose.Words.Loading.ResourceLoadingAction.Skip;
    }
}

Also, you can set User Provided image in ResourceLoadingCallback. Please let us know if the mentioned approaches can fit your requirements.