galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.14k stars 169 forks source link

Getting PDFUsedFont for a font that's already in PDF. #295

Open suniltandan opened 6 years ago

suniltandan commented 6 years ago

I looked through the documentation and found the following ways to add text:

var font = pdfWriter.getFontForFile('./arial.ttf');
var textOptions = {font:font,size:11,colorspace:'gray',color:0x00};
 cxt.writeText('Paths',250,250,textOptions);

//OR 
cxt.BT();
            cxt.k(0,0,0,1);
            cxt.Tf(font,11);
            cxt.Tm(1,0,0,1,250,250);
            cxt.Tj("Hello World");
            cxt.ET();

However both of these method require PDFUsedFont which needs to be read from a file.
Is there a way to use the font that's already in PDF? For example using the Object having PDFName of 'Font' which is retrieved via:

pdfWriter.getModifiedFileParser().parseNewObject(11).toJSObject()

Thanks in advance.

tonybranfort commented 5 years ago

Comments in #120 from galkahana might help re "Is there a way to use the font that's already in the PDF?".