我正在使用此示例将 java swing JFrame 转换为 pdf:export jcomponent to pdf with itext。问题是当我的框架包含像 čěř... 这样的 UTF-8 字符时。导出的文档中缺少这些字符。如何在我的 PDF 中打开这些字符?
更新:
我尝试您的示例,但出现异常:
ExceptionConverter: com.itextpdf.text.DocumentException: Font 'fonts/verdana.ttf,1' with 'Identity-H' is not recognized.
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:699)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:606)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:549)
at com.itextpdf.text.pdf.DefaultFontMapper.awtToPdf(DefaultFontMapper.java:107)
at com.itextpdf.text.pdf.PdfGraphics2D.getCachedBaseFont(PdfGraphics2D.java:1082)
at com.itextpdf.text.pdf.PdfGraphics2D.setFont(PdfGraphics2D.java:1075)
at javax.swing.JComponent.paintChildren(JComponent.java:855)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at javax.swing.JComponent.paintChildren(JComponent.java:874)
at javax.swing.JComponent.printChildren(JComponent.java:1214)
at javax.swing.JComponent.paint(JComponent.java:1049)
at javax.swing.JComponent.print(JComponent.java:1183)
at GUI.PlayOffPanel.export(PlayOffPanel.java:322)
看起来导入 .ttf 字体(如 verdana 或 times)存在一些问题,但举例来说,您添加的字体是有效的。但我真的很想使用 Verdana 字体所以还在寻找答案