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

Free Support Forum - aspose.com

Reading HTML document from a URL and converting into PDF

Hi,

I am trying to download an HTML file from a URL , this cannot be saved onto disc and therefore after download needs to be converted into PDF.

This is for our customer who is already using Aspose for word and PDF but this time we need to extend this functionality for HTML files.

Please can you tell exactly how we can achieve this.

Regards

Hi Umer,


Thanks for your inquiry. Please check following documentation link for the details/code snippet to render HTML to PDF. Hopefully it will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,

Dear Tilal,

I have followed the sample but unfortunately the converted document is un readable. I have attached the Sample HTML document along the output pdf pages. Please help.

Regards

Hi Umer,


Thanks for your feed back. I am afraid while testing the scenario with Aspose.Pdf for .NET 9.1.0, we are unable to replicate the issue. Please download and try latest version of Aspose.Pdf for .NET, it will fix the issue.

Best Regards,


Thanks Tilal. that solved the problem but we will also have to update the Aspose.PDF dll on customer environment and hope it doesn't break any thing.

One more question, do you have any example for MHT to PDF conversion using same scenario? i.e. mht files is stored as a URL link and we need to download this, convert to PDF without storing on disc.

Thanks

Hi Umer,


Thanks for your inquiry. We have recently introduce the MHT to PDF feature. Please check following documentation link for the details and code snippet. You can read MHT URL link into stream and use it for the conversion. Hopefully it will help you to accomplish the task. Please feel free to contact us if you find any issue, we will be more than happy to help you.


Best Regards,

Hi Tilal,


Our customer has reported one more problem regarding HTML reference file to PDF conversion. The referee comment includes some monetary figures with currency sign such as pound E.g. "£ 2.5 Million" whereas the converted PDF file is not showing £ sign and a box instead. Please see the attached HTML reference and converted PDF file screenshot.

Following is the code lines for HTML document to PDF conversion.


// Create a request for the URL.
WebRequest request = WebRequest.Create(documentURI);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();

MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions(documentURI);

// use the new conversion engine
options.UseNewConversionEngine = true;

// load HTML file
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(stream,options);
crmAccess.pdfDocuments.Add(pdfDoc);

Please can you help to identify the issue?

Thanks

Hi Umer,


Thanks for your inquiry. I have tested the scenario with Aspose.Pdf for .NET 9.2.1 and unable to replicate the issue. Please download and try latest version of Aspose.Pdf for .NET and share the results. Hopefully it will help you to resolve the issue.

HtmlLoadOptions htmloptions
= new HtmlLoadOptions();<o:p></o:p>

// use the new conversion engine

htmloptions.UseNewConversionEngine = true;

htmloptions.PageInfo.Width = 900;

htmloptions.PageInfo.Height = 590;

// load HTML file

Document doc = new Document(myDir + "ReferenceSampleCurrency.html", htmloptions);

doc.Save(myDir+"HTMLtoPDFDOM.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,

Unfortunately the problem is still not resolved. I have downloaded the latest version of Aspose.PDF(9.2.1) and used this in code but this time pound sign is even converted into more strange value.

Please see the attachment. Please can you try downloading HTML file from URI and reading into memory stream and convert into PDF, essentially same way I did and this way you might be able to reproduce the issue!

Thanks

Hi Umer,


Thanks for your feedback. We are looking into your query and will get back to you soon.

Best Regards,

Hi Umer,

We are sorry for the inconvenience caused. While testing the scenario with the latest version of Aspose.Pdf for .NET 9.2.1 using URL for the HTML to PDF conversion, we have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWNET-37008 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,