首页 > 解决方案 > ICEpdf 查看器无法正确渲染字体

问题描述

我有一门课程可以在 JFrame 中使用 ICEpdf 6.2.2(maven 存储库中的最新版本)测试 ICEpdf 查看器。当我打开 PDF 时,我试图在 Ubuntu 的默认 PDF 查看器中呈现它,它显示正确,但是,当在 ICEpdf 查看器中显示时,字体间距错误,实际字体被替换为无衬线字体。这是我的ICEpdf 查看器默认的 Ubuntu PDF 查看器中的GCC 手册的屏幕截图。我曾经收集手册中使用的字体是什么。在我的代码中,我设置为,这并没有解决问题。我的代码如下:pdffontsorg.icepdf.core.awtFontLoadingtrue

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.io.File;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.util.PropertiesManager;

public class TestPDF {

    JFrame mainFrame;
    final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    TestPDF window = new TestPDF();
                    window.mainFrame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public TestPDF() {
        mainFrame = new JFrame();
        mainFrame.setTitle("Test");
        mainFrame.setSize(new Dimension((int) (SCREEN_SIZE.getWidth() / 2), (int) (SCREEN_SIZE.getHeight() / 2)));
        try {
             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        PropertiesManager properties = new PropertiesManager(System.getProperties(), new Properties() {
            {
                setProperty("application.showLocalStorageDialogs", "false");
                setProperty("org.icepdf.core.awtFontLoading", "true");
            }
        }, ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE)) {
            {
                setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION, Boolean.FALSE);
                setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_FORMS, Boolean.FALSE);
                setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_UTILITY, Boolean.FALSE);
                setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ROTATE, Boolean.FALSE);
            }
        };
        SwingController controller = new SwingController();
        SwingViewBuilder factory = new SwingViewBuilder(controller, properties);
        JPanel viewerComponentPanel = factory.buildViewerPanel();
        controller.getDocumentViewController().setAnnotationCallback(
                new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

        try {
            File pdf = new File(this.getClass().getResource("/pdfTest/gcc.pdf").toURI());
            controller.openDocument(pdf.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        mainFrame.add(viewerComponentPanel);
    }
}

pdffonts输出:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
PNWIQB+CMBX12                        Type 1            Builtin          yes yes yes      7  0
URLEKE+CMR10                         Type 1            Builtin          yes yes yes      8  0
ZXGTJI+CMCSC10                       Type 1            Builtin          yes yes yes      9  0
YPVIBW+CMTT10                        Type 1            Builtin          yes yes yes     18  0
LNUCPW+CMSY10                        Type 1            Builtin          yes yes no      19  0
XLCDGX+CMR12                         Type 1            Builtin          yes yes yes     49  0
GPANTX+CMMI12                        Type 1            Builtin          yes yes no      50  0
TOPQZD+CMTT12                        Type 1            Builtin          yes yes yes     51  0
DOAFRX+CMMI10                        Type 1            Builtin          yes yes no     124  0
HMFXDM+CMTI10                        Type 1            Builtin          yes yes yes    804  0
FEUAVN+CMSL10                        Type 1            Builtin          yes yes yes   2558  0
DISGYX+CMSLTT10                      Type 1            Builtin          yes yes yes   2626  0
RQLRQN+CMTT9                         Type 1            Builtin          yes yes yes   2634  0
FRMZZY+CMR9                          Type 1            Builtin          yes yes yes   2635  0
KGBAZG+CMB10                         Type 1            Builtin          yes yes yes   2832  0
BNSWRJ+SFRM1095                      Type 1            Custom           yes yes no    3233  0
HSQXWC+CMR7                          Type 1            Builtin          yes yes no    3527  0
GINCXO+CMMI7                         Type 1            Builtin          yes yes no    4887  0
FFYKXD+CMSS10                        Type 1            Builtin          yes yes yes   4963  0
PXBGHL+CMSY7                         Type 1            Builtin          yes yes no    4989  0
QUTMWC+CMSY9                         Type 1            Builtin          yes yes no    5049  0
GXLYQS+CMSL9                         Type 1            Builtin          yes yes yes   6771  0
BCUDVF+CMBXTI10                      Type 1            Builtin          yes yes yes   7002  0
PQILTH+CMMI9                         Type 1            Builtin          yes yes no    7364  0
WOJFXW+CMR8                          Type 1            Builtin          yes yes yes  12564  0

标签: javaswingfontsicepdf

解决方案


推荐阅读