parseFromFileBuffer(pdfBuffer) { // Read the PDF file into a typed array so PDF.js can load it. let rawData = new Uint8Array(pdfBuffer); domFacade.setGlobalDom(); return PDFJSLib.getDocument({ data: rawData, // Try to export JPEG images directly if they don't need any further processing. nativeImageDecoderSupport: PDFJSLib.NativeImageDecoding.DISPLAY }).then((doc) => this.parseDocument(doc)) .then(() => this.metaDataHandler); }
renderPage(page) { if (!this.svgWriter) { return; } let viewport = page.getViewport(this.getPageViewportScale(page)); return page.getOperatorList().then((opList) => { let svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs); svgGfx.embedFonts = true; return svgGfx.getSVG(opList, viewport); }).then((svgDomElement) => { return this.svgWriter.writeSvgPage(page, svgDomElement); }); }
loadingTask.promise.then(function(doc) { const numPages = doc.numPages; console.log('# Document Loaded'); console.log('Number of Pages: ' + numPages); return doc.getPage(pageNum).then(function(page) { console.log('# Page ' + pageNum); let textContent; return page.getTextContent().then(function(content) { const strings = content.items.map(function(item, index, array) { let str = item.str; if (index === 0 || item.transform[5] !== array[index-1].transform[5]) { str += '\n'; textContent = strings.join(''); console.log(textContent); }).then(function() { writeFile('file.txt', textContent); });
loadingTask.promise.then(function(doc) { const numPages = doc.numPages; lastPromise = doc.getMetadata().then(function (data) { if (data.metadata) { return doc.getPage(pageNum).then(function (page) { const viewport = page.getViewport({ scale: 1.0, }); return page.getTextContent({normalizeWhitespace:true}).then(function (content) { const strings = content.items.map(function(item, index, array) { let str = item.str; if (index > 0 && item.transform[5] !== array[index-1].transform[5]) { str = '\n' + str; }).then(function () { lastPromise = lastPromise.then(loadPage.bind(null, i)); }).then(function () { console.log('# End of Document');