Skip to content

Tab character renders as Ampersand in Edge #1531

@Deepak4188

Description

@Deepak4188

PLEASE FILL THIS TEMPLATE AS MUCH AS POSSIBLE. REMOVE IRRELEVANT PARTS.

Describe the bug

When we visits a bookmark, it creates a chunk with tab character, and when \t is used it is rendered as & while opening in Microsoft edge whereas the same PDF is rendered fine (& is not shown) in Chrome and Adobe.

To Reproduce

Sample code:

    // https://github.com/LibrePDF/OpenPDF/issues/1024
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
    document.open();
    document.add(new Paragraph(new Chunk("Hello\tWorld")));
    document.add(new Paragraph(new Chunk("\t")));
    document.add(new Paragraph(new Chunk("Hello\tWorld")));
    document.close();

Expected behavior

\t should be rendered as * * (space only).

Screenshots

Image Image

System

(please complete the following information)

  • OS: Windows 11
  • Used font: Helvetica (Cp1252 encoding)
  • OpenPDF version: 2.0.2

Your real name

Deepak Chandra Sharma

Additional context

Also when I changes fallback font to render \t character, it works fine in Edge also.

Actual:
// Check if the chunk content is text
if (chunk.getContent().chars().allMatch(c -> (c >= 0x00 && c <= 0xFF))) {
// translation of the font-family to a PDF font-family
baseFont = f.getCalculatedBaseFont(false);
} else {
// translation to the embeddable free font
try {
baseFont = BaseFont.createFont("font-fallback/LiberationSans-Regular.ttf",
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Works fine with:
// Check if the chunk content is text
if (chunk.getContent().chars().allMatch(c -> (c >= 0x20 && c <= 0xFF))) {
// translation of the font-family to a PDF font-family
baseFont = f.getCalculatedBaseFont(false);
} else {
// translation to the embeddable free font
try {
baseFont = BaseFont.createFont("font-fallback/LiberationSans-Regular.ttf",
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Additionally we tried other fonts like Times-Roman, Courier and Helvetica but the same behaviour was being observed.

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
Font font =new Font(BaseFont.createFont("Times-Roman", BaseFont.CP1252, BaseFont.EMBEDDED));
document.add(new Paragraph(new Chunk("Hello\tWorld", font)));
document.add(new Paragraph(new Chunk("\t", font)));
document.add(new Paragraph(new Chunk("Hello\tWorld", font)));

    document.close();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions