PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
BaseFont baseFont = BaseFont.createFont("src/Components/font/cyr.ttf", BaseFont.CP1250, BaseFont.EMBEDDED);
Font font = new Font(baseFont, 14, Font.NORMAL);
document.add(new com.itextpdf.text.Paragraph(text, font));
Font font = FontFactory.getFont("/fonts/DejaVuSans.ttf", "cp1251", BaseFont.EMBEDDED, 10);
try (FileOutputStream fs = new FileOutputStream(file)) {
Document document = new Document();
PdfWriter.getInstance(document, fs);
document.open();
Paragraph paragraph = new Paragraph();
paragraph.add(new Paragraph("Привет", normalFont));
document.add(paragraph);
document.close();
}
catch (DocumentException exc) {}
catch (IOException exc) {}