HTML to PDF C# using Aspose.PDF for .NET | Unsupported font style

Hi I am having problem converting HTML string to PDF by using DOM approach.

Here’s my sample code snippet.
license.SetLicense(lic_path);
string fullPath = “C:\OutputFolder\“
string emailBodyDetails = “<SPAN style=”“FONT-FAMILY: Calibri, ‘Segoe UI’, Meiryo, ‘Microsoft YaHei UI’, ‘Microsoft JhengHei UI’, ‘Malgun Gothic’, sans-serif; FONT-SIZE: 16px””>Content.”;
using (FileStream fs = new FileStream(fullPath + “Output.html”, FileMode.Create))
{
using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
{
w.WriteLine(emailBodyDetails);
}
fs.Close();
}
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(fullPath + “Output.html”, new HtmlLoadOptions() { UseNewConversionEngine = true });
doc.Save(fullPath + “Output.pdf”);

I am getting error during conversion, and I found out that the html font style Meiryo is causing it, as when I remove the style from the string, it works fine. May I know how can this font be included in my document conversion?

At the same time, can I know which font are not supported in Aspose and what can I do to ensure all types of fonts are supported because we are not able to control the style usage in html as those contents are coming in from emails.

Hi ShiJien,


Thanks for using our API.

I have tested the scenario using Aspose.Pdf for .NET 9.4.0 where I have made a slight change in your code and as per my observations, the PDF file is properly being generated. I do not have Segoe UI, Meiryo and other custom fonts installed over my system. Can you please share which version of API you are using and also please share the resource font file so that we can retest the scenario at our end. We are sorry for your inconvenience.

[C#]

string emailBodyDetails = “<SPAN
style=“FONT-FAMILY: Calibri, ‘Segoe UI’, Meiryo, ‘Microsoft YaHei UI’,
‘Microsoft JhengHei UI’, ‘Malgun Gothic’, sans-serif; FONT-SIZE:
16px”>Content.
;<o:p></o:p>

using (FileStream fs = new FileStream( "c:/pdftest/tempOutput.html", FileMode.Create))

{

using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))

{

w.WriteLine(emailBodyDetails);

}

fs.Close();

}

Aspose.Pdf.Document doc = new Aspose.Pdf.Document("c:/pdftest/tempOutput.html", new HtmlLoadOptions() { UseNewConversionEngine = true });

doc.Save("c:/pdftest/Conversion_Output.pdf");

I am using Aspose.Pdf for .NET 9.2.1.0 at my end. I do not have the resource font file, as this is a sample html email content I retrieved from database with some random font style which I have no control over it. I keep getting error during conversion, until I remove the Meiryo style from the html and it works fine. Please advise. Thank you.

Hi ShiJien,


As shared in my earlier post, I have tested the scenario using Aspose.Pdf for .NET 9.4.0 and I am unable to notice any issue. The Meiryo style information is present in HTML and resultant PDF is created. Can you please try using the latest release and in case the problem still persists, please share some sample application.

Please note that I have tested the scenario in VisualStudio 2012 application with target platform as .NET Framework 4.0 running over Windows 7 (x64) with English (US) as regional language setting.

Hi,


Can you please try again with this HTML string as follow, using the same approach I’ve mentioned above.

Content

For this HTML, it will fail. I am suspecting maybe the tag is having conflict with the the Meiryo style. You can only have either one of them in the HTML. If both presence, conversion will fail. Please advice on how can this be fix. I need this urgently. Thank you.

shijient_ppc:
Hi,

Can you please try again with this HTML string as follow, using the same approach I’ve mentioned above.

Content

For this HTML, it will fail. I am suspecting maybe the tag is having conflict with the the Meiryo style. You can only have either one of them in the HTML. If both presence, conversion will fail. Please advice on how can this be fix. I need this urgently. Thank you.
Hi ShiJien,

Thanks for sharing the details.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWNET-37250. We will
investigate this issue in details and will keep you updated on the status of a
correction. <o:p></o:p>

We apologize for your inconvenience.

Hi,


Thank you, but can you please escalate this issue to urgent fix? We are having this issue and it has been affecting our production routine. Thanks again.

Hi ShiJien,


Since we recently have been able to notice this issue, and until or
unless we have investigated and have figured out the actual reasons of this
problem, we might not be able to share any timelines by which this problem will
be resolved.

However, as soon as we have made some significant progress towards the
resolution of this issue, we would be more than happy to update you with the
status of correction. Please be patient and spare us little time. Your patience
and comprehension is greatly appreciated in this regard.

Hi,


I would like to know the status of this ticket. It’s been a month since the ticket has been logged. As I previously stated, I hope Aspose can release a fix to this issue sooner, as it really affecting our production routine. We are unable to manage those emails which contain these html that is causing error during conversion. Your immediate response and support is greatly appreciated. Thank you.

Hi ShiJien,


Thanks for your inquiry. We have a good news for you, your above reported issue has been fixed in upcoming release i.e. Aspose.Pdf for .NET 9.6.0. Hopefully this version will be released in first week of September, 2014. However, as soon as it is released and gets available for download, we will notify you via this forum thread.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37250) have been fixed in Aspose.Pdf for .NET 9.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi, I have just tested the scenario above with the new release of Aspose.Pdf for .NET 9.6.0. but the problem doesn’t seem to have solved. Can you please verify the ticket <span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-ansi-language:
EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>PDFNEWNET-37250? Immediate attention from you is greatly appreciated. Thank you.

Hi, is there any support personel that can assist me in this? I am really looking urgently into some help. Thank you.

Hi ShiJien


Thanks for your inquiry. I am afraid we tested again following code with Aspose.Pdf for .NET 9.6.0 and unable to replicate the issue. We will appreciate it if you please share a console application to show the problem. We will test the scenario and will update you accordingly.

string emailBodyDetails = “<SPAN
style=“FONT-FAMILY: Calibri, ‘Segoe UI’, Meiryo, ‘Microsoft YaHei UI’,
‘Microsoft JhengHei UI’, ‘Malgun Gothic’, sans-serif; FONT-SIZE:
16px”>Content
”;<o:p></o:p>

using (FileStream fs = new FileStream(myDir+"tempOutput.html", FileMode.Create))

{

using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))

{

w.WriteLine(emailBodyDetails);

}

fs.Close();

}

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(myDir+"tempOutput.html", new HtmlLoadOptions() { UseNewConversionEngine = true });

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


We are sorry for the inconvenience caused.

Best Regards,

[quote user=“tilal.ahmad”]Hi ShiJien


Thanks for your inquiry. I am afraid we tested again following code with Aspose.Pdf for .NET 9.6.0 and unable to replicate the issue. We will appreciate it if you please share a console application to show the problem. We will test the scenario and will update you accordingly.

string emailBodyDetails = “<SPAN
style=“FONT-FAMILY: Calibri, ‘Segoe UI’, Meiryo, ‘Microsoft YaHei UI’,
‘Microsoft JhengHei UI’, ‘Malgun Gothic’, sans-serif; FONT-SIZE:
16px”>Content
”;<o:p></o:p>

using (FileStream fs = new FileStream(myDir+"tempOutput.html", FileMode.Create))

{

using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))

{

w.WriteLine(emailBodyDetails);

}

fs.Close();

}

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(myDir+"tempOutput.html", new HtmlLoadOptions() { UseNewConversionEngine = true });

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


We are sorry for the inconvenience caused.

Best Regards,
[/quote]
Hi,

Please try with this string.
string emailBodyDetails = "Content";

Hi ShiJien,


Thanks for your feedback. We have tested the scenario with your html string and noticed the same NullReferenceException. So we have requested our development team to revisit and fix the issue on priority. We will keep you updated about the issue resolution progress.

We are truly sorry for the inconvenience.

Best Regards,

Hi,


Thank you very much. I hope to hear from you the soonest possible on this issue as I am really in urgent to apply this fix which have been already affecting our production work routine. Thanks again.

Hi,


The development team has been intimated to check this problem in details and they will try fixing it as quickly as possible. As soon as we have some further updates, we will let you know.

We are really sorry for the regression bug.

Hi ShiJien,


Thanks for your patience.

As per our current estimates, we plan to get this problem resolved in Aspose.Pdf for .NET 9.8.0 which is planned to release in November-2014 (but still its not a promise). We will try our level best to get the problem fixed by said time. Your patience and comprehension is greatly appreciated in this regard.

Hi,


Can I know how’s the progress of this ticket? Is the fix ready? Thanks.