Hello,
I try to load an html file from an url in order to convert it to a pdf file.
I obtain the following mistake : buffer cannot be null. Is there a way to solve this ?
Here is the code that I use :
class Program { static void Main(string[] args) { ImageLoadingWithCredentialsHandler imageLoadingWithCredentialsHandler = new ImageLoadingWithCredentialsHandler(); Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions(); loadOptions.ResourceLoadingCallback = imageLoadingWithCredentialsHandler;
Aspose.Words.Document elise = new Aspose.Words.Document("http://localhost:81/Elise.html", loadOptions); elise.Save(@"C:\temp\test\output\Elise.pdf");} }<span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ImageLoadingWithCredentialsHandler</span> : <span style="color:#2b91af;">IResourceLoadingCallback</span> { <span style="color:blue;">public</span> ImageLoadingWithCredentialsHandler() { mWebClient = <span style="color:blue;">new</span> <span style="color:#2b91af;">WebClient</span>(); } <span style="color:blue;">public</span> <span style="color:#2b91af;">ResourceLoadingAction</span> ResourceLoading(<span style="color:#2b91af;">ResourceLoadingArgs</span> args) { <span style="color:blue;">if</span> (args.ResourceType == <span style="color:#2b91af;">ResourceType</span>.Image) { <span style="color:#2b91af;">Uri</span> uri = <span style="color:blue;">new</span> <span style="color:#2b91af;">Uri</span>(args.Uri); <span style="color:green;">// Download the bytes from the location referenced by the URI.</span> <span style="color:blue;">byte</span>[] imageBytes = mWebClient.DownloadData(args.Uri); args.SetData(imageBytes); <span style="color:blue;">return</span> <span style="color:#2b91af;">ResourceLoadingAction</span>.UserProvided; } <span style="color:blue;">else</span> { <span style="color:blue;">return</span> <span style="color:#2b91af;">ResourceLoadingAction</span>.Default; } } <span style="color:blue;">private</span> <span style="color:#2b91af;">WebClient</span> mWebClient; }</pre></pre></div>