Here's some code that fixes the rendering of this file:

try (PDDocument doc = Loader.loadPDF(new File("20251103 mail test2.pdf")))
{
    PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm(null); // avoids any fixup
    PDResources dr = acroForm.getDefaultResources();
    PDFont font = PDType0Font.load(doc, new FileInputStream("SimSun-UNSECURE.ttf"), false); // source https://fontzone.net/font-details/simsun
    dr.put(COSName.getPDFName("SimSun"), font);
    acroForm.refreshAppearances();
    PDFRenderer r = new PDFRenderer(doc);
    ImageIO.write(r.renderImageWithDPI(0, 300), "png", new File("page1.png"));     ImageIO.write(r.renderImageWithDPI(6, 300), "png", new File("page7.png"));
}

The font I have on windows is a ttc file so I can't embed it. I downloaded a simsun.ttf file from a dubious source and used that to replace the file in the default resources.

However saving this file brings a file that is now incorrectly displayed in Adobe Reader.

That is of course only for this file. Not embedding fonts is always a risk 😬

Tilman


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to