[
https://issues.apache.org/jira/browse/PDFBOX-4400?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16718854#comment-16718854
]
kevin guerin commented on PDFBOX-4400:
--------------------------------------
just change
{code:java}
String ttfName = "org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf";
URL url = FontMapper.class.getClassLoader().getResource(ttfName);
{code}
to
{code:java}
String ttfName = "/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf";
URL url = FontMapper.class.getResource(ttfName);
{code}
doesn't work with java11 and jlink
change
{code:java}
URL url = PDType1Font.class.getClassLoader().getResource(resourceName);
{code}
to
{code:java}
URL url = PDType1Font.class.getResource(resourceName);
{code}
doesn't in my test
my final working test is
{code:java}
Path path =
Paths.get(URI.create("jrt:/modules/pdfbox/org/apache/pdfbox/resources/afm/" +
afmName + ".afm"));
// String resourceName = "org/apache/pdfbox/resources/afm/" + afmName +
".afm";
// URL url = PDType1Font.class.getResource(resourceName);
if (path != null)
{
InputStream afmStream = Files.newInputStream(path);
try
{
AFMParser parser = new AFMParser(afmStream);
FontMetrics metric = parser.parse(true);
STANDARD14_AFM_MAP.put(fontName, metric);
}
finally
{
afmStream.close();
}
}
else
{
throw new IOException(path + " not found");
}
{code}
the problem is its not generic because you can name the modules part of the
link as you want to (the name of the directory is in the command of jlink).
therefore people who want to use jlink need to change this. may be passing
throw a properties file could do the job?
is PdfBox 3.0 means to work with java11 and jlink?
> jlink loading police.afm files
> ------------------------------
>
> Key: PDFBOX-4400
> URL: https://issues.apache.org/jira/browse/PDFBOX-4400
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 2.0.13
> Environment: java11 jlink windows moditect
> Reporter: kevin guerin
> Assignee: Tilman Hausherr
> Priority: Major
> Labels: jdk9
> Fix For: 2.0.14, 3.0.0 PDFBox
>
>
> hello everybody,
>
> I've got a problem with this trace on jlink on java11 (it works without jlink)
>
> {code:java}
> // Exception in thread "JavaFX Application Thread"
> java.lang.ExceptionInInitializerError
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.PDFont.<init>(PDFont.java:112)
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.PDType0Font.<init>(PDType0Font.java:176)
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:83)
> at
> [email protected]/org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:146)
> at
> [email protected]/org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
> at
> [email protected]/org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:848)
> at
> [email protected]/org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:503)
> at
> [email protected]/org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:477)
> at
> [email protected]/org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:150)
> at
> [email protected]/org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:254)
> at
> [email protected]/org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:245)
> at
> [email protected]/org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:179)
>
> Caused by: java.lang.RuntimeException: java.io.IOException:
> org/apache/pdfbox/resources/afm/Courier-Bold.afm not found
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.Standard14Fonts.<clinit>(Standard14Fonts.java:97)
> ... 36 more
> Caused by: java.io.IOException:
> org/apache/pdfbox/resources/afm/Courier-Bold.afm not found
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.Standard14Fonts.addAFM(Standard14Fonts.java:134)
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.Standard14Fonts.addAFM(Standard14Fonts.java:103)
> at
> [email protected]/org.apache.pdfbox.pdmodel.font.Standard14Fonts.<clinit>(Standard14Fonts.java:50)
> ... 36 more
> {code}
>
> I think the problem comes from the fact that while using jlink the classpath
> does not exist and it need to be loaded by an another way that the classpath
> one.
>
> the path should look like something like :
> {code:java}
> // Path path =
> Paths.get(URI.create("jrt:/pdfbox/org/apache/resources/afm/police.afm"));
> {code}
> modules here is managed by moditect (maven plugin to help creating
> module-info descriptor) and contain all dependancies of the project
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]