Converting an HTML document with images to PDF

Hi Aspose support team,

I have Aspose.Words and I’m trying to convert an HTML document that includes image URLs to PDF.

I’m currently trying to embed the image (base64) on the HTML document and then using the resulting binary with method Aspose.Words.Doc2PDF. Still the image isn’t rendered in the PDF.

What is the recommended procedure for this?

Thanks in advance.

Hi

Thanks for your request. Could you please attach your input HTML document here for testing? I will investigate the issue and provide you more information.
Best regards,

I’ve added an example in attach of the post.

The picture we’re trying to have converted is the one put inline (base 64) although we’ll also be able to have them separately (URL) added, if that’s part of the procedure you’ll recommend.

I’m also having trouble passing some styles to the PDF, for example font type.

For an HTML like:<font class="Apple-style-span" face="Arial">

I still get Times New Roman (or similar) on the PDF.
Thanks in advance for the help on these 2 issues.

Hello
Thank you for additional information. Regarding base64 data in your HTML, currently Aspose.Words does not support base64 data upon HTML import. We will consider an ability to support this and provide you more information. As a workaround please try using direct url to image.
Also I managed to reproduce the problem with font. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.
Best regards.

Hi,

using a URL the image is not included in the HTML binary that is sent to Doc2PDF. That’s why we tried embedding it in the HTML.

Could you, perhaps, provide an example of the procedure (HTML and C# code) you’re recommending?

Hello

Thanks for your inquiry. Actually, images usually are not included into HTML document. When you open HTML, like the following, using Aspose.Words, it will get image from URL and embed it into a final document.

Best regards,

Thanks Andrey,

I was referring about an example on to have such HTML being converted into a PDF. Can this be done with Aspose.Words? If so, could you provide an example? If not, how could this be done (also with an example, if possible)?

Hello

Thanks for your request. Please see the following code:

// Open HTML
Document doc = new Document(@"in.html");
// Save output document
doc.Save(@"out.pdf");

or you can try using this code to insert HTML and save as PDF

// Create an empty Document Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(@"<img src='img.png' />");
// Save output document
doc.Save(@"out.pdf");

Hope this helps.
Best regards,

Hi Andrey,

we’ve replaced our use of Aspose.Words.Doc2PDF method by the code you’ve recommended and it worked pretty well.

Thanks!

Actually, everything is working fine with the images, but now we are having problems with the inline fonts.
Basically the inline fonts are not showing up on the document.
thank you,
Vasco

Hi Vasco,

Thanks for your inquiry. Your request has been linked to the appropriate issue. We will be sure to inform you of any developments regarding this problem.
Best regards,

The issues you have found earlier (filed as 9180) have been fixed in this update.

The issues you have found earlier (filed as 19752) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

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