jochenberger Github contribution chart
jochenberger Github Stats
jochenberger Most Used Languages

Activity

27 Sep 2022

Issue Comment

Jochenberger

Problem with embedded fonts and PDF/A generation

I try to embedded/use fonts using your AutoFont example with Noto Sans in scanned directory. Times-Roman and Times-Bold are listed in font properties in Foxit Phantom PDF. How can I find which elments in HTML causes the usage of this fonts?

In inline css I use

body {
    font-family:'Noto Sans';
} 

I even try to generate a PDF/A compliant document and always get

 java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:372)
	at java.base/java.util.ArrayList.get(ArrayList.java:459)
	at com.openhtmltopdf.pdfboxout.PdfBoxFastOutputDevice.drawString(PdfBoxFastOutputDevice.java:393)
	at com.openhtmltopdf.pdfboxout.PdfBoxTextRenderer.drawString(PdfBoxTextRenderer.java:52)
	at com.openhtmltopdf.render.AbstractOutputDevice.drawText(AbstractOutputDevice.java:101)
	at com.openhtmltopdf.render.InlineText.paint(InlineText.java:171)
	at com.openhtmltopdf.render.InlineLayoutBox.paintInline(InlineLayoutBox.java:279)
	at com.openhtmltopdf.render.simplepainter.SimplePainter.paintInlineContent(SimplePainter.java:170)
	at com.openhtmltopdf.render.simplepainter.SimplePainter.paintLayer(SimplePainter.java:72)
	at com.openhtmltopdf.render.PageBox.paintMarginAreas(PageBox.java:430)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.paintPageFast(PdfBoxRenderer.java:882)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.writePDFFast(PdfBoxRenderer.java:619) 

Any ideas?

Remarks: I use stlyes shown on Page Featutes wiki page. I suppose I have to set font-family in any matcher (@Page..) Is this correct?

Forked On 27 Sep 2022 at 08:42:01

Jochenberger

We should at least report a more helpful error to help people find the actual problem.

Commented On 27 Sep 2022 at 08:42:01
Issue Comment

Jochenberger

IndexOutOfBoundsException in PdfBoxFastOutputDevice using PDF/UA

Using Java 8, Windows, openhtmltopdf v1.0.10.

I tried recreating the example from https://github.com/danfickle/openhtmltopdf/issues/352

HTML:

<html>
<head>
<style>
@page {
  margin: 50px 20px;
  @bottom-left {
    content: element(whatever);
  }
}
</style>
</head>
<body>
<div style="position: running(whatever);">
  This is some <strong>richly</strong> styled html!<br/>
  <span style="color: red;">This is another line.</span>
</div>

<h1>Rest of content</h1>

<p>Etc, etc, etc...</p>

</body>
</html> 

with the Java code:

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.usePdfUaAccessbility(true);
builder.toStream(out);
builder.run(); 

and I get the exception:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:668)
	at java.util.ArrayList.get(ArrayList.java:444)
	at com.openhtmltopdf.pdfboxout.PdfBoxFastOutputDevice.drawString(PdfBoxFastOutputDevice.java:390)
	at com.openhtmltopdf.pdfboxout.PdfBoxTextRenderer.drawString(PdfBoxTextRenderer.java:60)
	at com.openhtmltopdf.render.AbstractOutputDevice.drawText(AbstractOutputDevice.java:105)
	at com.openhtmltopdf.render.InlineText.paint(InlineText.java:171)
	at com.openhtmltopdf.render.InlineLayoutBox.paintInline(InlineLayoutBox.java:284)
	at com.openhtmltopdf.render.simplepainter.SimplePainter.paintInlineContent(SimplePainter.java:170)
	at com.openhtmltopdf.render.simplepainter.SimplePainter.paintLayer(SimplePainter.java:72)
	at com.openhtmltopdf.render.PageBox.paintMarginAreas(PageBox.java:487)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.paintPageFast(PdfBoxRenderer.java:920)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.writePDFFast(PdfBoxRenderer.java:628)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPdfFast(PdfBoxRenderer.java:564)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPDF(PdfBoxRenderer.java:490)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPDF(PdfBoxRenderer.java:427)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.createPDF(PdfBoxRenderer.java:409)
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.run(PdfRendererBuilder.java:46) 

"Workaround": Removing builder.usePdfUaAccessbility(true); creates the PDF.

Forked On 27 Sep 2022 at 08:40:51

Jochenberger

Looks like a duplicate of #654

Commented On 27 Sep 2022 at 08:40:51