I have problem with converting .pptx slides to .pdf document on my server. I use itextpdf 5.5.10 and apache poi 3.15 for .pptx files. If the text contains Chinese characters, the positioning of all characters is bad. On my local machine (windows 7) I have no problems. This is what it looks like on my machine
And this is what it looks like on the server (CentOS Linux release 7.4.1708 (Core) with ubuntu font family installed)

This is the (java) code I use to do the conversion:
PdfContentByte canvas = writer.getDirectContent();
UnicodeFontMapper mapper = new UnicodeFontMapper();
for (XSLFSlide slide : ppt.getSlides()) {
PdfTemplate template = canvas.createTemplate(width, height);
Graphics2D g2d = new PdfGraphics2D(template, width, height, mapper);
// default rendering options
DrawFactory.getInstance(g2d).fixFonts(g2d);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
//Draw slide
slide.draw(g2d);
canvas.addTemplate(template, 0, 0);
g2d.dispose();
document.newPage();
}
UnicodeFontMapper class:
public class UnicodeFontMapper extends DefaultFontMapper {
@Override
public BaseFont awtToPdf(Font font) {
//using own fonts
String fontFamily = "ArialUni";
registerFontFamily(fontFamily);
int style = com.itextpdf.text.Font.NORMAL;
if (font.isBold()) {
if (font.isItalic()) {
style = com.itextpdf.text.Font.BOLDITALIC;
} else {
style = com.itextpdf.text.Font.BOLD;
}
}
com.itextpdf.text.Font pdfFont = FontFactory.getFont(fontFamily, BaseFont.IDENTITY_H, true, font.getSize(), style);
return pdfFont.getBaseFont();
}
I use ArialUni.ttf font. As I understand I'm missing something on my server but I can't figure out what exactly.
