I am having trouble getting some HTML converted to PDF to render Unicode checkboxes.
\u2612 ☒ and \u2610 ☐
They appear ok in the word conversion, but are missing in PDF
Here is the same code
using Telerik.Documents.ImageUtils;
using Telerik.Windows.Documents.Flow.FormatProviders.Html;
using Telerik.Windows.Documents.Flow.Model;
namespace Web.Tests.Pdf;
public class PdfRenderTests
{
private readonly IHtmlToWordConverter _htmlToWordConverter = new HtmlToWordConverter();
string path = "c:\\\\temp\\\\pdf\\\\";
[Fact]
public void CanRenderCheckbox()
{
var html = "<span class=\"checkbox\">\u2612 Yes \u2610 No</span>";
var htmlDocument = _htmlToWordConverter.ConvertHtmlToWord(html);
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
using var memoryStream = new MemoryStream();
docxProvider.Export(htmlDocument, memoryStream);
var documentBytes = memoryStream.ToArray();
File.WriteAllBytes($"{path}Test.docx", documentBytes);
var pdfBytes = PdfConverter.ConvertDocxToPdf(documentBytes);
File.WriteAllBytes($"{{path}}Test.pdf", pdfBytes);
}
}
public interface IHtmlToWordConverter
{
RadFlowDocument ConvertHtmlToWord(string html);
}
public class HtmlToWordConverter : IHtmlToWordConverter
{
public RadFlowDocument ConvertHtmlToWord(string html)
{
var htmlFormatProvider = new HtmlFormatProvider();
return htmlFormatProvider.Import(html);
}
}
public static class PdfConverter
{
static PdfConverter()
{
var defaultImagePropertiesResolver = new ImagePropertiesResolver();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver =
defaultImagePropertiesResolver;
}
public static byte[] ConvertDocxToPdf(byte[] docxBytes)
{
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
var document = docxProvider.Import(docxBytes);
using var memoryStream = new MemoryStream();
pdfProvider.Export(document, memoryStream);
return memoryStream.ToArray();
}
}
PDF Output:
Word Output