开发者

iText, Java - Two Certain Greek characters don't appear on the PDF

开发者 https://www.devze.com 2023-03-23 10:43 出处:网络
I was working with iText in java and tried to make a simple program that creates a PDF file with Greek text in it.

I was working with iText in java and tried to make a simple program that creates a PDF file with Greek text in it. Here is part of my code:

(...)
**public String url = "C:/Windows/Fonts/arial.ttf";**
public int size = 12;
**public String GREEK_CODEPAGE = "Cp1253";**
(...)
    public void createPdf(String filename, String INPUT)throws DocumentException, IOException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        **BaseFont fonty = BaseFont.createFont(url , GREEK_CODEPAGE , true);
        Font myfonty = new Font(fonty, size, Font.NORMAL);
        document.add(new Paragraph(INPUT, myfonty));**
        document.close();        
    }

So, I call this method and it creates my PDF file, but for some reason the characters "Δ"(Capital Delta) and "Ω"(Capital Omega) have been replaced everywhere in my text with spaces (all other characters, including lower delta and lower omega, are okay). I'm not sure if this is some glitch, or something I did. I tried using other codepages and fonts that support Greek characters, but those 2 characters were still 开发者_运维知识库missing. Can you help me? Thanks in advance.


To fix probelm with Greek letters change the encoding:

BaseFont fonty = BaseFont.createFont(url, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
fonty.setSubset(true);

Optionally you may embed only the subset of the font (second line).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号