Hello,
The issue is that pdf generation fails when an emoji appears at the line break.
Environment
asp.net core 8
Aspose Version: 25.7.0
Windows
Editioin: Windows 11 Enerprise
Added sample code
Program.zip (818 Bytes)
It sounds like you’re encountering an issue with PDF generation when an emoji appears at a line break. This can happen due to the way certain characters, like emojis, are handled in text rendering.
Cause: The issue likely arises from the font not supporting emojis or the way line breaks are processed when emojis are included in the text.
Solution: Here are some steps you can take to troubleshoot and potentially resolve the issue:
-
Update Aspose.PDF: Ensure you are using the latest version of Aspose.PDF. The version you mentioned (25.7.0) may have bugs that have been fixed in later releases.
-
Font Support: Make sure that the font you are using supports emojis. Not all fonts include emoji characters, which can lead to rendering issues. You might want to try using a font known for good emoji support, such as “Segoe UI Emoji” or “Noto Color Emoji”.
-
Text Formatting Options: If you’re using
TextFragment
orTextBuilder
, check the text formatting options. You can set properties likeTextState.Font
to ensure the correct font is being used. -
Handling Line Breaks: If the emoji is causing a line break issue, consider replacing the emoji with a placeholder or removing it before generating the PDF. You can then handle the emoji separately if needed.
-
Error Handling: Implement error handling in your code to catch exceptions during PDF generation. This can help you identify the exact point of failure.
Here’s a minimal code snippet to illustrate how you might set the font for a TextFragment
:
using Aspose.Pdf;
using Aspose.Pdf.Text;
var document = new Document();
var page = document.Pages.Add();
var textFragment = new TextFragment("Hello 🌍");
textFragment.TextState.Font = FontRepository.FindFont("Segoe UI Emoji");
page.Paragraphs.Add(textFragment);
document.Save("output.pdf");
Next Steps: Try these steps and see if they help resolve the issue. If the problem persists, please provide any error messages or additional details about the context in which the error occurs.
Let me know if this resolves your issue!
The problem is not with the HTML. Here is the error that occurs during pdf generation:
error - “truncated surrogate pair”
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): PDFNET-60451
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.