[ 
https://issues.apache.org/jira/browse/PDFBOX-3260?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15186163#comment-15186163
 ] 

John Aylward edited comment on PDFBOX-3260 at 3/9/16 12:29 AM:
---------------------------------------------------------------

I'm hitting a snag and I'm not sure if it's a bug or if I'm doing something 
wrong. I'm trying to place my TTF file on the classpath and load it as a 
resource:

this works fine (not a resource):
{code:title=Works.java|borderStyle=solid}
try (final InputStream fontStream = new FileInputStream(
        new File(
                "/home/user/path/to/my/project/src/main/resources/micrenc.ttf"))

) {
    this.micrFont = PDType0Font.load(this.pdf, fontStream);
}
{code}


But this gives me the "head is mandatory" error:

{code:title=Fails.java|borderStyle=solid}
try (final InputStream ts = Fails.class.getResourceAsStream("/micrenc.ttf");
        final InputStream fontStream = new 
ByteArrayInputStream(IOUtils.toByteArray(ts))
) {
    this.micrFont = PDType0Font.load(this.pdf, fontStream);
}
{code}

The resource is definately found (when it isn't I instead get an NPE) and I 
can't for the life of me figure out why this would be different than loading 
the file directly.

I placed the IOUtils.toByteArray in there to see if it changed anything, but 
indeed, it's the same error as just using the resource stream directly.

If it makes a difference at all, this is running in a Tomcat 7 (7.0.62) 
container 


was (Author: johnjaylward):
I'm hitting a snag and I'm not sure if it's a bug or if I'm doing something 
wrong. I'm trying to place my TTF file on the classpath and load it as a 
resource:

this works fine (not a resource):
{code:title=works.java|borderStyle=solid}
try (final InputStream fontStream = new FileInputStream(
        new File(
                "/home/user/path/to/my/project/src/main/resources/micrenc.ttf"))

) {
    this.micrFont = PDType0Font.load(this.pdf, fontStream);
}
{code}


But this gives me the "head is mandatory" error:

{code:title=fails.java|borderStyle=solid}
try (final InputStream ts = fails.class.getResourceAsStream("/micrenc.ttf");
        final InputStream fontStream = new 
ByteArrayInputStream(IOUtils.toByteArray(ts))
) {
    this.micrFont = PDType0Font.load(this.pdf, fontStream);
}
{code}

The resource is definately found (when it isn't I instead get an NPE) and I 
can't for the life of me figure out why this would be different than loading 
the file directly.

I placed the IOUtils.toByteArray in there to see if it changed anything, but 
indeed, it's the same error as just using the resource stream directly.

If it makes a difference at all, this is running in a Tomcat 7 (7.0.62) 
container 

> IOException "head is mandatory" when importing a TTF file
> ---------------------------------------------------------
>
>                 Key: PDFBOX-3260
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3260
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 1.8.11, 2.0.0
>         Environment: Linux, Oracle Java8
>            Reporter: John Aylward
>
> I'm trying to import this font 
> (http://www.1001fonts.com/micr-encoding-font.html#character-map)  but I get 
> the following exception:
> {quote}
> java.io.IOException: head is mandatory
>       at org.apache.fontbox.ttf.TTFParser.parseTables(TTFParser.java:181)
>       at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:150)
>       at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:106)
>       at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:78)
> {quote}
> A similar issue happens with 1.8.11 as well.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to