I have Aspose.Html v 25.3.0 for C#.NET with a temporary license. This very simple html below is coming out with the first h2 using some crazy font that I don’t even seem to have installed on my machine. Html and pdf screenshot below.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style>
.text-center {
text-align: center;
}
.tab1 {
margin-left: 25px;
}
.title-margin {
margin: 5px;
}
.text-white {
color:white;
}
span.labeled { display: inline-block; vertical-align: top; }
span.agent-labeled span.label { display: block; text-align: left; border-top: 1px solid black;width: 500px; }
span.date-labeled span.label { display: block; text-align: left; border-top: 1px solid black;width: 150px; }
body{
font-family: Arial, Helvetica, sans-serif;
}
.question {
font-weight: bold;
width: 100%;
}
.answer {
width: 100%;
margin-bottom: 10px;
}
.tab {
margin-left: 20px;
}
</style>
</head>
<body>
<div class="text-center">
<strong>
<div>
<h2 class="title-margin">Dynamic Case Details</h2>
</div>
</strong>
</div>
</body>
</html>
image.png (4.6 KB)
@miles.rosemire
It seems that you are experiencing an issue with the font rendering of the first <h2>
tag when converting HTML to PDF using Aspose.Html. This can happen if the font specified in your HTML is not available on your system or if there are issues with the font fallback mechanism.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
-
Check Font Availability: Ensure that the font you are using (in this case, Arial, Helvetica, or sans-serif) is installed on your machine. If the font is not available, the rendering engine may substitute it with a different font, which could lead to unexpected results.
-
Specify Font in CSS: You can explicitly set the font for the <h2>
tag in your CSS to ensure that it uses a specific font. For example:
h2 {
font-family: Arial, Helvetica, sans-serif;
}
-
Use PdfSaveOptions: When converting HTML to PDF, you can specify options that might help with font handling. For instance, you can set the PdfSaveOptions
to include embedded fonts. Here’s a basic example of how to do this:
var options = new Aspose.Html.Saving.PdfSaveOptions
{
// Other options can be set here
EmbedFonts = true // This ensures that fonts are embedded in the PDF
};
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.pdf");
-
Test with Different HTML: Sometimes, simplifying the HTML can help identify the issue. Try converting a minimal HTML snippet with just the <h2>
tag to see if the problem persists.
-
Update Aspose.Html: Ensure that you are using the latest version of Aspose.Html, as updates may include bug fixes and improvements related to font rendering.
If the issue continues after trying these steps, consider sharing a more detailed example or the specific output you are seeing, as this can help in diagnosing the problem further.
Feel free to reach out if you need more assistance!
Sources:
[1]: ConvertHTMLToPDF.cs
What version is this example from? EmbedFonts is not a property on PdfSaveOptions.
It was the <strong>
tag around the h2. I removed it and the problem went away. How random!
@miles.rosemire
Would you kindly share your sample code snippet that you used for PDF generation? We will test the scenario in our environment and address it accordingly.
byte[] bytes = [];
using (var streamProvider = new SingleMemoryStreamProvider())
{
var saveOptions = new PdfSaveOptions();
saveOptions.PageSetup.AnyPage.Margin = new Aspose.Html.Drawing.Margin(20);
if (landscape)
{
saveOptions.PageSetup.AnyPage.Size = new Aspose.Html.Drawing.Size(1320, 1020);
}
Converter.ConvertHTML(html, ".", saveOptions, streamProvider);
var stream = streamProvider.GetStream("", "");
bytes = ((MemoryStream)stream).ToArray();
}
@miles.rosemire
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): HTMLNET-6245
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.