1

I'm sorry for my English. I'm trying to create table with PdfPTable(iText library). Table show me empty column![enter image description here][1]

public class CreatePDF {
File file;
BaseFont bf;
Font f_title;
Font f_text;

public void setFont() throws DocumentException, IOException{
    try{
        bf = BaseFont.createFont("/fonts/Times_New_Roman.ttf", BaseFont.IDENTITY_H , BaseFont.EMBEDDED); 
        f_title = new Font(bf, 14 );
        f_text = new Font(bf);
    }catch(Exception ex){
        ex.printStackTrace();
    }
}

public void make_invoice() throws DocumentException, IOException{
    setFont();
    Document doc = new Document(PageSize.A4);
    Desktop d = Desktop.getDesktop();
    try{
        file = new File("invoice.pdf");
        PdfWriter.getInstance(doc, new FileOutputStream(file));
        doc.open();
        Paragraph title = new Paragraph();
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(f_title);
        title.add("Счет фактура");//this work!

        doc.add(create_table());

        doc.close();

    }catch(Exception ex){
        ex.printStackTrace();
    }
}

public PdfPTable create_table() throws DocumentException{
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setSpacingBefore(5f);

    PdfPCell cell;

    Phrase ph = new Phrase("Номер");//it's doesn't work ((
    ph.setFont(f_text);

    cell = new PdfPCell(ph);
    table.addCell(cell);
    table.addCell("Nuber");

    return table;
}

I tried use other fonts but it doesn't help me(((

How can i fix this problem?

inoob
  • 11
  • 1
  • 2

1 Answers1

0

When you use setFont(), you change the font of the Phrase for all the content that is added after the font was set. The content "Номер" was already present in the Phrase before you changed it. Hence "Номер" was represented in the default font Helvetica. As Helvetica doesn't know how to represent Cyrillic glyphs, the text wasn't rendered.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • 1
    if you indicate the proper way to do with an example it would help understand you... still dont understand your answer – Pipo Dec 06 '21 at 19:03