有没有办法将数学字母数字符号(unicode 中的符号)保存到 VB.NET 中的 PDF 或 Word 文档?
Is there a way to save mathematical alphanumerical symbols (the ones that are in unicode) to a PDF or Word document in VB.NET?
基本上,我需要从文本文件中提取问题并将其格式化为数学考试中的问题格式。
现在,我正在使用 PDFsharp 执行此操作,但它总是将字母数字符号(例如,)保存为框。
我尝试从 PDFsharp 上的示例中复制并得到这个
Dim document As New PdfSharp.Pdf.PdfDocument
Dim page As PdfSharp.Pdf.PdfPage = document.AddPage()
Dim gfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(page)
Dim tf As New PdfSharp.Drawing.Layout.XTextFormatter(gfx)
Dim options As New PdfSharp.Drawing.XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode)
Dim font As New PdfSharp.Drawing.XFont("LastResort", 10, PdfSharp.Drawing.XFontStyle.Regular, options)
tf.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Left
tf.DrawString(questionArray(i)), font, PdfSharp.Drawing.XBrushes.Black, New PdfSharp.Drawing.XRect(0, 0, page.Width.Point, page.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft)
Dim filename As String = "test" + Str(i).Trim + ".pdf"
document.Save(filename)
Process.Start(filename)
我知道我不需要一直重复 "PdfSharp.Pdf" 的东西,我的计划是在我正确保存角色后将其全部清理干净。
根据 https://www.fileformat.info/info/unicode/block/mathematical_alphanumeric_symbols/fontsupport.htm
,Last Resort 是一种包含 unicode 符号和数学字母数字块的字体
我的最终目标是获取像 "f(x) = 5[^2] + (k+7) + k where k is a real constant." 这样的基本 .txt 文件并将其保存为 PDF 以类似于真正的数学考试问题。
那么,是否有更好的方法或让 PDFsharp 做到这一点的方法?
PDFsharp 中的 Unicode 支持适用于 0x0000 到 0xffff 范围内的字符,只要您使用支持这些字符的字体。
数学字母数字符号在 U+1D400..U+1D7FF 范围内。您必须修补 PDFsharp 才能使用它们。截至今天(2019 年 12 月),它们还不支持开箱即用。
在您的代码段中,您将 "LastResort" 作为字体名称。 Windows 中是否安装了同名字体?你能用它吗? Word 还是写字板?
也许试试 "Arial" 或 "Tahoma" 或 "Verdana"。
您在调试器中看到正确的字符串了吗?可能问题在于文本文件的格式或用于打开它的编码。
更新:
LastResort 中的所有角色看起来都像方块。数学试卷没有好的选择:
请尝试不同的字体。
基本上,我需要从文本文件中提取问题并将其格式化为数学考试中的问题格式。
现在,我正在使用 PDFsharp 执行此操作,但它总是将字母数字符号(例如,)保存为框。
我尝试从 PDFsharp 上的示例中复制并得到这个
Dim document As New PdfSharp.Pdf.PdfDocument
Dim page As PdfSharp.Pdf.PdfPage = document.AddPage()
Dim gfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(page)
Dim tf As New PdfSharp.Drawing.Layout.XTextFormatter(gfx)
Dim options As New PdfSharp.Drawing.XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode)
Dim font As New PdfSharp.Drawing.XFont("LastResort", 10, PdfSharp.Drawing.XFontStyle.Regular, options)
tf.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Left
tf.DrawString(questionArray(i)), font, PdfSharp.Drawing.XBrushes.Black, New PdfSharp.Drawing.XRect(0, 0, page.Width.Point, page.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft)
Dim filename As String = "test" + Str(i).Trim + ".pdf"
document.Save(filename)
Process.Start(filename)
我知道我不需要一直重复 "PdfSharp.Pdf" 的东西,我的计划是在我正确保存角色后将其全部清理干净。 根据 https://www.fileformat.info/info/unicode/block/mathematical_alphanumeric_symbols/fontsupport.htm
,Last Resort 是一种包含 unicode 符号和数学字母数字块的字体我的最终目标是获取像 "f(x) = 5[^2] + (k+7) + k where k is a real constant." 这样的基本 .txt 文件并将其保存为 PDF 以类似于真正的数学考试问题。
那么,是否有更好的方法或让 PDFsharp 做到这一点的方法?
PDFsharp 中的 Unicode 支持适用于 0x0000 到 0xffff 范围内的字符,只要您使用支持这些字符的字体。
数学字母数字符号在 U+1D400..U+1D7FF 范围内。您必须修补 PDFsharp 才能使用它们。截至今天(2019 年 12 月),它们还不支持开箱即用。
在您的代码段中,您将 "LastResort" 作为字体名称。 Windows 中是否安装了同名字体?你能用它吗? Word 还是写字板?
也许试试 "Arial" 或 "Tahoma" 或 "Verdana"。
您在调试器中看到正确的字符串了吗?可能问题在于文本文件的格式或用于打开它的编码。
更新:
LastResort 中的所有角色看起来都像方块。数学试卷没有好的选择:
请尝试不同的字体。