Dear support,
We already had a license for Aspose.Pdf version 7.6, but couldn’t make it work to generate pdf from WebClient response. Can you send me an example or do we have to upgrade to latest version and make it work like following code:
using (var pdfStream = new MemoryStream())
using (var client = new WebClient { UseDefaultCredentials = true }) {
var response = client.DownloadData(url);
using (var stream = new MemoryStream(response) {
using (var reader = new StreamReader(stream)) {
var html = reader.ReadToEnd();
var options = new HtmlLoadOptions(url);
var pdfDocument = new Document(new MemoryStream(Encoding.UTF8.GetBytes(html)), options) {
PageInfo = { IsLandscape = true }
};
pdfDocument.Save(pdfStream, SaveFormat.Pdf);
}
}
}
return pdfStream.ToArray();
}
I have downloaded a trial with temp license and when we use the above code it is currently not displaying the correct styles and images in the pdf because of relative urls.
Hi Ahmet,
Thanks, I have attached my code and input / output as screendumps. As you can see it only contains the images with full urls and styles are missing because of relative urls. Furthermore, most of the links will be broken because of relative urls too.
Hi Ahmet,
Here is my source for same page - I think I have to define basePath somewhere just like in HtmlLoadOptions.
Hi Ahmet,
Thanks for sharing the source HTML. I am afraid I am unable to test your HTM code for PDF conversion as even full url are not working at my end e.g. “http://my.danskenet.net/hr/dk/SiteCollectionImages/174x57fortsat/174x57_Meeting.jpg
”. We will appreciate it if you please some valid HTML so we will check this and guide you accordingly.
Furthermore, yes you need to pass basePath as parameter to HtmlLoadOptions for external resources during HTML to PDF conversion.
We are sorry for the inconvenience caused.
Best Regards,
It is an intranet application - I was thinking you just had to look at it. You can test with http://www.danskebank.dk/da-dk/erhverv/Pages/Erhverv.aspx
, it works in the same way with relative urls.
And I have tried to define the basePath but it only fixed the hyperlinks, not the styles and images.
Hi Ahmet,
Hi Ahmet,
The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan