Html to PDF conversion by url missing images & styles with relative urls

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 for your inquiry. Yes it is recommend to use new DOM approach(Aspose.Pdf) for HTML to PDF conversion instead old generator(Aspose.Pdf.Generator). It is more improved , efficient and old generator will be obsolete in near future.

Moreover, we will appreciate it if you please share your sample code and input/output documents here. We will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

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,


Thanks for sharing the details.

I am able to notice the formatting issue in OutputPage.jpg image file. However please share the resource/input HTML file, so that we can test the scenario in our environment. We are sorry for this inconvenience.

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,


Thanks for sharing additional information. I am testing your scenario and will update you soon.

Best Regards,

Hi Ahmet,


Thanks for your patience. I have tested and noticed that external resources are not being honored as expected, so logged a ticket PDFNEWNET-39750 in our issue tracking system for further investigation and resolution.

We are sorry for the inconvenience caused.

Best Regards,

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