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

Tilman Hausherr commented on PDFBOX-5473:
-----------------------------------------

IMHO this font table has been botched. I entered the Korean "font family" into 
google translate and it means "Hyundai Harmony L". Thus nothing surprising, or 
that would make no sense in english. They used "harmony" in other parts of the 
english table so I don't understand why they skipped it. Maybe try to find a 
more recent version of that font.

You can get the font family name with this code:
{code:java}
String name = ttFont.getName(NameRecord.NAME_FONT_FAMILY_NAME, 
NameRecord.PLATFORM_WINDOWS, NameRecord.ENCODING_WINDOWS_UNICODE_BMP, 1042)
{code}
You could also implement a more general "desperate" fallback if the name is 
null:
{code:java}
for (NameRecord nr : ttf.getNaming().getNameRecords())
{
        if (nr.getNameId() == NameRecord.NAME_FONT_FAMILY_NAME)
        {
                name = nr.getString();
        }
}
{code}

> Can't get the family font name of the specified font.
> -----------------------------------------------------
>
>                 Key: PDFBOX-5473
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5473
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.24, 2.0.26
>            Reporter: bai yuan
>            Priority: Major
>         Attachments: image-2022-07-06-05-54-22-068.png, 현대하모니 L.ttf
>
>
> Run the following code, you will see the family name of this font is null.
> {code:java}
> System.setProperty("sun.java2d.cmm", 
> "sun.java2d.cmm.kcms.KcmsServiceProvider");  
> PDDocument doc = new PDDocument();
> PDPage page = new PDPage(PDRectangle.A4);
> doc.addPage(page);
> PDPageContentStream contentStream = new PDPageContentStream(doc, page);       
>  TrueTypeFont ttFont = new TTFParser().parse(new File("현대하모니 L.ttf"));
> PDFont font = PDType0Font.load(doc, ttFont, true);        
> String name = ttFont.getNaming().getFontFamily();
> contentStream.beginText();
> contentStream.newLineAtOffset(50, 800);
> contentStream.setFont(font, 48);
> contentStream.showText("abc");
> contentStream.endText();       
> contentStream.close();
> doc.save("pdfbox.pdf");
> doc.close();
> System.out.println(name); {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to