I have a class to test an ICEpdf viewer in a JFrame with ICEpdf 6.2.2, the newest in the maven repository. When I open the PDF I'm trying to render in Ubuntu's default PDF viewer it displays correctly, however, when displayed in the ICEpdf viewer the font spacing is wrong and the actual font is replaced with a sans serif font. Here are screenshots of the GCC manual in my ICEpdf viewer and the default Ubuntu PDF viewer. I have used pdffonts
to gather what the fonts used in the manual are. In my code I have set org.icepdf.core.awtFontLoading
to true
, which didn't fix the issue. My code is the following:
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
output:
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