LibrePDF / OpenPDF

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.
Other
3.56k stars 586 forks source link

Font.BOLD not working, when the Euro sign (€) is in the Text. #646

Open tellschaft opened 2 years ago

tellschaft commented 2 years ago

Describe the bug

After the migration from iText to OpenPDF 1.3.26 the Property Font.BOLD is not working when the Text in the Paragraph contains an Euro sign (€).

To Reproduce Code to reproduce the issue

  1. Sample Code
public class TestPDFEuro {

  public static void main(String[] args) {

    File path = new File("test_euro" + ".pdf");

    try (FileOutputStream fileOutputStream = new FileOutputStream(path)) {

      Document document = new Document();
      PdfWriter.getInstance(document, fileOutputStream);

      document.open();

      float[] widths = { 1, 1, 1, 1 };

      PdfPTable table = new PdfPTable(widths);

      table.setWidthPercentage(80);

      table.setSpacingAfter(20);

      table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

      int fontSizeText = 10;

      Font font = new Font(Font.HELVETICA, fontSizeText, Font.BOLD);

      Paragraph p1 = new Paragraph("TEST1", font);

      table.addCell(p1);

      Paragraph p2 = new Paragraph("10 €", font);

      table.addCell(p2);

      Paragraph p3 = new Paragraph("TEST2", font);

      table.addCell(p3);

      Paragraph p4 = new Paragraph("10 Euro", font);

      table.addCell(p4);

      table.completeRow();

      document.add(table);

      document.close();

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

Expected behavior

With the old iText Version (from 2009) it works.

Screenshots

OpenPDF:

2022-01-10 17_12_39-test_euro pdf - Adobe Acrobat Reader DC (32-bit)

iText:

2022-01-10 17_12_57-test_euro_iText pdf - Adobe Acrobat Reader DC (32-bit)

System (please complete the following information):

Additional context

tellschaft commented 2 years ago

Replacing

Font font = new Font(Font.HELVETICA, fontSizeText, Font.BOLD);

with

Font font = FontFactory.getFont(FontFactory.HELVETICA, fontSizeText, Font.BOLD);

fixes the Problem.

tellschaft commented 2 years ago

I will try working on this

Hello, Thank your for the Support,

Is it maybe the same Problem as in #665 ?