import { Files } from 'polar-shared/src/util/Files' ; import url from 'url' ; import * as PDFJS from 'pdfjs-dist' ; xdescribe ( 'PDF' , function ( ) { xit ( "basic" , async function ( ) { const buffer = await Files . readFileAsync ( "/home/burton/Downloads/1010.3003v1.pdf" ) ; const uint8 = toArray ( buffer ) ; const filePath = "/home/burton/incremental-reading/.stash/The Toyota Way _ 14 Management Principles from the World's Greatest Manufac.pdf" ; if ( ! await Files . existsAsync ( filePath ) ) { throw new Error ( "File does not exist at path: " + filePath ) ; } const fileURL = url . format ( { protocol : 'file' , slashes : true , pathname : filePath , } ) ; const pdfLoadingTask = PDFJS . getDocument ( fileURL ) ; const doc = await pdfLoadingTask . promise ; const metadata = await doc . getMetadata ( ) ; if ( metadata . metadata && metadata . metadata . get ( 'dc:title' ) ) { console . log ( "FIXME !!!" ) ; } console . log ( "metadata: " , metadata ) ; console . log ( "numPages: " + doc . numPages ) ; console . log ( "fingerprint: " + doc . fingerprint ) ; } ) ; } ) ; function toArray ( buf ) { if ( ! buf ) { return undefined ; } if ( buf . constructor . name === 'Uint8Array' ) { return buf ; } if ( typeof buf === 'string' ) { buf = Buffer . from ( buf ) ; } var a = new Uint8Array ( buf . length ) ; for ( var i = 0 ; i < buf . length ; i ++ ) { a [ i ] = buf [ i ] ; } return a ; }