我在使用 iText XMLWorkerHelper 将 HTML 转换为 PDF 时遇到了麻烦。文档生成良好,但最终没有一些中欧字符(克罗地亚字母,如 č、ć、đ、ž)。
当我在没有 XMLWorkerHelper 的情况下编写文本并定义字体时,databese 中的相同文本被正确写入:
Dim fntArial As BaseFont = BaseFont.CreateFont("Helvetica", BaseFont.CP1250, BaseFont.NOT_EMBEDDED)
Dim fontText10 As Font = New Font(fntArial, 10)
但是当我使用 XMLWorkerHelper CE 时,字符会丢失。
Dim pdfDokument As New Document()
Dim docContent As String = "<style>" & _
"@font-face {font-family: 'Arial'; src: url('fonts/arial.ttf') format('truetype');}" & _
"body, td, div, span{font-family: 'Arial'; color: #253f60; font-size: 12px;}" & _
...
"</style>" & _
"HTML content from database"
Dim wrtPDF As PdfWriter = PdfWriter.GetInstance(pdfDokument, New FileStream(Request.PhysicalApplicationPath & docName, FileMode.Create))
pdfDokument.Open()
Dim worker As XMLWorkerHelper = XMLWorkerHelper.GetInstance
worker.ParseXHtml(wrtPDF, pdfDokument, New StringReader(docContent))
如何将 CE 字体嵌入 PDF 文档并将其设置为 XMLWorkerHelper 的默认字体?