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

Jens Bruhn commented on PDFBOX-490:
-----------------------------------

My own workaround is attached. If someone has a better workaround or some more 
ideas, I would really like to see them here.

It still doesn't work for special characters with "Symbol"-Font (created with 
LibreOffice PDF-Export). Any ideas?

Greetings,
 jens


Class PDTrueTypeFont:

private final Map<String, String> _normalizedFontNameSet = new HashMap<String, 
String>();
private final Map<String, Font> _fontCache = new HashMap<String, Font>();

@Override
    public Font getawtFont() throws IOException
    {
        PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) 
getFontDescriptor();
        final String fontName = fd.getFontName();

        if (_fontCache.keySet().contains(fontName))
        {
            awtFont = _fontCache.get(fontName);
        }
        else
        {
            final String fontAndStyle = 
fontName.substring(fontName.indexOf("+") + 1, fontName.length() - 2);
            final String pureFontName = fontAndStyle.contains("-") ? 
fontAndStyle.substring(0, fontAndStyle.indexOf("-"))
                    : fontAndStyle;
            final String pureStyleName = fontAndStyle.contains("-") ? 
fontAndStyle.substring(fontAndStyle.indexOf("-") + 1) : "";
            int style = 0;

            if (pureStyleName.toLowerCase().contains("bold"))
            {
                style |= Font.BOLD;
            }
            if (pureStyleName.toLowerCase().contains("italic"))
            {
                style |= Font.ITALIC;
            }

            final String newFontName = getLocalFontName(pureFontName);
            awtFont = new Font(newFontName == null ? "Arial" : newFontName, 
style, 10);
            _fontCache.put(fontName, awtFont);
        }

        return awtFont;
    }

    private String getLocalFontName(final String name)
    {
        final Iterator<String> iterator = 
_normalizedFontNameSet.keySet().iterator();
        final String compareName = name.toLowerCase();
        String result = null;

        while (iterator.hasNext())
        {
            final String fontName = iterator.next();

            if (compareName.contains(fontName))
            {
                result = _normalizedFontNameSet.get(fontName);
                break;
            }
        }

        return result;
    }

> Pdf Printing of text from embedded fonts
> ----------------------------------------
>
>                 Key: PDFBOX-490
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-490
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 0.8.0-incubator
>         Environment: Windows XP, JRE 1.6
>            Reporter: Steve Poling
>            Assignee: Andreas Lehmkühler
>         Attachments: filled.pdf
>
>
> When printing from utility PrintPdf, text is rendered in the wrong typeface. 
> The correct typeface is embedded within the PDF (Embedded Subset) as a 
> TrueType font with an ANSI encoding. It may be noted that the AcroFields in a 
> Courier typeface render correctly.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to