You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to add Regular and Bold variants of https://fonts.google.com/specimen/Raleway font. Not directly through the this library, but by using FlyingSaucer. I think though, it might be an issue with LibrePDF.
I get exception:
java.lang.ArrayIndexOutOfBoundsException: Index 4100 out of bounds for length 1068
at com.lowagie.text.pdf.TrueTypeFontSubSet.checkGlyphComposite(TrueTypeFontSubSet.java:365)
at com.lowagie.text.pdf.TrueTypeFontSubSet.flatGlyphs(TrueTypeFontSubSet.java:360)
at com.lowagie.text.pdf.TrueTypeFontSubSet.process(TrueTypeFontSubSet.java:148)
at com.lowagie.text.pdf.TrueTypeFontUnicode.writeFont(TrueTypeFontUnicode.java:478)
at com.lowagie.text.pdf.FontDetails.writeFont(FontDetails.java:410)
at com.lowagie.text.pdf.PdfWriter.addSharedObjectsToBody(PdfWriter.java:1333)
at com.lowagie.text.pdf.PdfWriter.close(PdfWriter.java:1266)
at com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:851)
at com.lowagie.text.Document.close(Document.java:535)
at org.xhtmlrenderer.pdf.ITextRenderer.createPDF(ITextRenderer.java:406)
at org.xhtmlrenderer.pdf.ITextRenderer.createPDF(ITextRenderer.java:326)
at internal.project.package.PdfRenderer.renderPdf(PdfRenderer.java:45)
To Reproduce
Code to reproduce the issue
public class Test {
public static void main(String[] args) {
System.out.println("True Types (embedded)");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2: creation of the writer-object
PdfWriter.getInstance(document, new FileOutputStream("unicode.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content to the document
Font font =
FontFactory.getFont(
"fonts/Raleway-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12);
String text1 = "This is the quite popular True Type font 'Raleway'.";
document.add(new Paragraph(text1, font));
} catch (DocumentException | IOException de) {
System.err.println(de.getMessage());
}
// step 5: we close the document
document.close();
}
}
Original code with Flyingsaucer:
@Service
@Slf4j
public class PdfRenderer {
private static final List<String> FONTS =
List.of("fonts/Raleway-Regular.ttf", "fonts/Raleway-Bold.ttf");
private final TemplateEngine templateEngine;
public PdfRenderer(TemplateEngine templateEngine) {
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
resolver.setPrefix("templates/");
resolver.setSuffix(".html");
resolver.setTemplateMode(TemplateMode.HTML);
templateEngine.setTemplateResolver(resolver);
this.templateEngine = templateEngine;
}
public byte[] renderPdf(String templateName, Context context) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
ITextRenderer renderer = new ITextRenderer();
for (String font : FONTS) {
renderer.getFontResolver().addFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
}
renderer.setDocumentFromString(templateEngine.process(templateName, context));
renderer.layout();
renderer.createPDF(outputStream);
return outputStream.toByteArray();
} catch (Exception e) {
e.printStackTrace();
throw new PdfGenerationException("Error generating PDF", e);
}
}
}
Expected behavior
I would expect that Fonts are loaded and rendered. Trying test given above with direct usage of LibrePDF lib, it yields empty pdf. If I try another font, e.g. https://fonts.google.com/noto/specimen/Noto+Sans, it works.
Describe the bug
I am trying to add Regular and Bold variants of https://fonts.google.com/specimen/Raleway font. Not directly through the this library, but by using FlyingSaucer. I think though, it might be an issue with LibrePDF.
I get exception:
To Reproduce
Code to reproduce the issue
Original code with Flyingsaucer:
Expected behavior
I would expect that Fonts are loaded and rendered. Trying test given above with direct usage of LibrePDF lib, it yields empty pdf. If I try another font, e.g. https://fonts.google.com/noto/specimen/Noto+Sans, it works.
System
The text was updated successfully, but these errors were encountered: