Q: I need your help to extract embedded fonts from PDF file (attached
publication.pdf). I am using the following code
Obj fontObj =
pdfView.getDoc().getSDFDoc().getObj(vdpTxtFieldInfo.m_SDFObjNum);
// or fontObj.getEmbeddedFont();
//Filter filter = fontObj.getDecodedStream();
Filter filter = fontObj.getRawStream(true);
pdftron.Filters.FilterReader reader = new
pdftron.Filters.FilterReader(filter);
byte[] fontStream =
reader.read(fontObj.getRawStreamLength());
I get the Byte Stream. To test if I have done it correct. I output
this stream to a file. This is a True Type Font and subset is set to
false when extracting the PDF so all the Glyps are available. Firstly
when I click on the File, the Windows complain that the font is not
recoginzed. And also I tried with the following code
if (fontFile != null)
{
pdftron.PDF.Font pdfFont = null;
pdfFont =
pdftron.PDF.Font.createTrueTypeFont(pdfView.getDoc().getSDFDoc(),
fontFile, true);
PDFPageInfo.m_InfoLog.info("\n---PDF FONT OBJECT IS
CREATED.------" + pdfFont.getName() + "\n");
}
This throws following Exception
Message: The font file could not be opened or read
-------
A: You should use 'fontObj.getDecodedStream()' instead of
'fontObj.getRawStream(true)'. Calling getRawStream() would will return
a raw PDF data stream for a given stream which can be compressed and/
or encrypted.