Java iText7 UTF8 Characters

Viewed 34

I want to create an invoice as a pdf document. I have a problem with some letters of the Croatian alphabet. In the PDF there are the letters š,ž but the letters đ, č, ć are not displayed. How to solve the problem?

public static void createPDF(String pdfFilename) throws FileNotFoundException {
   
    try {
        
        String path = "invoice.pdf";
        PdfWriter pdfWriter = new PdfWriter(path);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);

        pdfDocument.setDefaultPageSize(PageSize.A4);
        Document document = new Document(pdfDocument);

        setHeader(document);
        setCompanyData(document);
        document.add(sp);
        setInvoiceNo(document);
        setCustomerAndPayment(document);


        document.close();


    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

And for example, this function

private static void setInvoiceNo(Document document) {
    try {
        float columnwidths[] = {570f / 2};

        Table table = new Table(columnwidths).setBorder(Border.NO_BORDER);
        table.setTextAlignment(TextAlignment.LEFT);
        table.setWidth(UnitValue.createPercentValue(100));

        table.addCell(new Cell().add("Račun broj: 751/22").setBorder(Border.NO_BORDER).setFont(montserrant_font));
        document.add(table);
    } catch (Exception e) {

    }

}

The sentence Račun broj: 751/22 in PDF is Raun broj: 751/22

The font is loaded well and supports those letters because it works without problems in the rest of the code

0 Answers
Related