Extract Font Name from PDF

Extract Font Name from PDF

I am using pdf.js to extract text from the pdf but the font name appears as&nbsp;<code>g_d0_f6</code>&nbsp;etc. I need the font name to use the appropriate table for converting to Unicode. Here is the code derived from pdf2svg.js sample:-

I am using pdf.js to extract text from the pdf but the font name appears as g_d0_f6 etc. I need the font name to use the appropriate table for converting to Unicode. Here is the code derived from pdf2svg.js sample:-

var fs = require('fs');
var util = require('util');
var path = require('path');
var stream = require('stream');

// HACK few hacks to let PDF.js be loaded not as a module in global space. require('./domstubs.js').setStubs(global);

var pdfjsLib = require('pdfjs-dist');

var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; var data = new Uint8Array(fs.readFileSync(pdfPath));

var loadingTask = pdfjsLib.getDocument({ data: data, nativeImageDecoderSupport: pdfjsLib.NativeImageDecoding.DISPLAY, }); loadingTask.promise.then(function(doc) { var lastPromise = Promise.resolve(); // will be used to chain promises var loadPage = function (pageNum) { return doc.getPage(pageNum).then(function (page) { return page.getTextContent().then(function (textContent) { console.log(textContent); }); }); };

for (var i = 1; i <= doc.numPages; i++) { lastPromise = lastPromise.then(loadPage.bind(null, i)); } return lastPromise; }).then(function () { console.log('# End of Document'); }, function (err) { console.error('Error: ' + err); });

Sample output:-

{ items: 
   [ { str: 'bl fp=k osQ ckjs esa cPpksa ls ckrphr djsa & ;g LowQy esa fdl le; dk n`'; gS\ cPps',
       dir: 'ltr',
       width: 396.2250000000001,
       height: 15,
       transform: [Array],
       fontName: 'g_d0_f1' },
     { str: 'D;k dj jgs gSa\ cPps dkSu&dkSu ls [ksy] [ksy j',
       dir: 'ltr',
       width: 216.1650000000001,
       height: 15,
       transform: [Array],
       fontName: 'g_d0_f1' },
     { str: 'g',
       dir: 'ltr',
       width: 6.42,
       height: 15,
       transform: [Array],
       fontName: 'g_d0_f1' },
     { str: 's gSa\ fp=k esa fdrus cPps gSa vkSj fdrus',
       dir: 'ltr',
       width: 173.865,
       height: 15,
       transform: [Array],
       fontName: 'g_d0_f1' },
     { str: 'cM+s gSa\ vkil esa dkSu D;k ckr dj jgk gksxk\ cPpksa ls fp=k esa lcosQ fy, uke lkspus',
       dir: 'ltr',
       width: 396.54000000000013,
       height: 15,
       transform: [Array],
       fontName: 'g_d0_f1' },
     { str: 'dks dgasaA',
       dir: 'ltr',
       width: 40.74,
       height: 15,
       transform: [Array],
       fontName: 'g_d0_f1' },
     { str: 'csVh cpkvks',
       dir: 'ltr',
       width: 66.725,
       height: 17,
       transform: [Array],
       fontName: 'g_d0_f2' },
     { str: 'csVh i<+kvksA',
       dir: 'ltr',
       width: 66.75899999999999,
       height: 17,
       transform: [Array],
       fontName: 'g_d0_f2' },
     { str: '2018-19',
       dir: 'ltr',
       width: 36.690000000000005,
       height: 10,
       transform: [Array],
       fontName: 'g_d0_f3' } ],
  styles: 
   { g_d0_f1: 
      { fontFamily: 'sans-serif',
        ascent: 0.837,
        descent: -0.216,
        vertical: false },
     g_d0_f2: 
      { fontFamily: 'sans-serif',
        ascent: 0.786,
        descent: -0.181,
        vertical: false },
     g_d0_f3: 
      { fontFamily: 'sans-serif',
        ascent: 0.9052734375,
        descent: -0.2119140625,
        vertical: false } } }

And here is the pdf that uses embedded fonts: http://ncert.nic.in/textbook/pdf/ahhn101.pdf

Here is a related question but the suggested commonObjs is empty: pdf.js get info about embedded fonts

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

JavaScript Tutorial: if-else Statement in JavaScript

This JavaScript tutorial is a step by step guide on JavaScript If Else Statements. Learn how to use If Else in javascript and also JavaScript If Else Statements. if-else Statement in JavaScript. JavaScript's conditional statements: if; if-else; nested-if; if-else-if. These statements allow you to control the flow of your program's execution based upon conditions known only during run time.

How to Retrieve full Profile of LinkedIn User using Javascript

I am trying to retrieve the full profile (especially job history and educational qualifications) of a linkedin user via the Javascript (Fetch LinkedIn Data Using JavaScript)

Java vs. JavaScript: Know The Difference

Java vs. JavaScript: Know the Difference, Java vs. JavaScript: What's the Difference? Java vs. JavaScript: Major Similarities and Differences. pros and cons of JavaScript and Java.