Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init (timestamp) {
const t = this;
this.loadingTask = pdfJsLib.getDocument({
url: this.url,
cMapUrl: '../../node_modules/pdfjs-dist/cmaps/',
cMapPacked: true
});
this.loadingTask.promise.then(async function(pdf) {
console.time('PDF_Render')
console.log('PDF loaded');
var container = document.querySelector(`.pdf-wrap`);
// for(var i = 0, len = pdf.numPages; i < len; i++) {
// await t.renderPage(pdf, i + 1, container)
// }
console.log(pdf.numPages);
var pages = await Promise.all(
Array.apply(null, Array(pdf.numPages)).map((item, index) => {
console.log(item, index)
async function extractPDFFile(input, output) {
let pdf = await pdfjsLib.getDocument({
data: input.array
});
// pdf files can have embedded properties; extract those
const meta = await pdf.getMetadata();
if (meta.info) {
if (meta.info.Author) {
output.author = meta.info.Author;
}
if (meta.info.Title) {
output.datasetTitle = meta.info.Title;
}
if (meta.info.Keywords) {
output.keywords = meta.info.Keywords.split(/,\s+/g);
loadPdf(pdfData) {
let loadingTask = pdfjsLib.getDocument({ data: pdfData });
loadingTask.promise.then((pdf) => {
this.numPages = pdf.numPages;
this.thePDF = pdf;
// let viewer = document.getElementById('canvasWrapper');
let viewer = this.canvasWrapper.nativeElement;
let page;
for (page = 1; page <= pdf.numPages; page++) {
let canvas = document.createElement("canvas");
viewer.appendChild(canvas);
this.renderPage(page, canvas);
}
setTimeout(() => {
function pageLoaded() {
// Loading document and page text content
pdfJsLib.getDocument({url: PDF_PATH}).then(function (pdfDocument) {
pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
var viewport = page.getViewport(PAGE_SCALE);
page.getTextContent().then(function (textContent) {
// building SVG and adding that to the DOM
var svg = buildSVG(viewport, textContent);
document.getElementById('pageContainer').appendChild(svg);
});
});
});
}
textLayerMode: 2
});
// FIXME: the scale is important here too...
//
pdfLinkService.setViewer(pdfElement);
//
// // Loading document.
// const url = '../../../docs/examples/pdf/bigtable.pdf';
const url = '../../../test.pdf';
pdfjsLib.GlobalWorkerOptions.workerSrc = '../../../node_modules/pdfjs-dist/build/pdf.worker.js';
const loadingTask = pdfjsLib.getDocument({
url,
cMapUrl: '../../../node_modules/pdfjs-dist/cmaps/',
cMapPacked: true,
pdfFindController: this.pdfFindController,
});
//
const pdfDocument = await loadingTask.promise;
pdfElement.setDocument(pdfDocument);
pdfLinkService.setDocument(pdfDocument, null);
pdfFindController.setDocument(pdfDocument);
}
init () {
const t = this;
this.loadingTask = pdfJsLib.getDocument({
url: this.url,
cMapUrl: '../../node_modules/pdfjs-dist/cmaps/',
cMapPacked: true
});
this.loadingTask.promise.then(async function(pdf) {
console.time('PDF_Render')
console.log('PDF loaded');
t.pdf = pdf
t.totalPage = pdf.numPages;
t.renderOnePage(1);
}).catch(function (reason) {
t.$emit('loaded');
console.error('Error: ', reason);
t.fileLoading = false;
t.error = "PDF load failed :(";
module.exports = function parsePDF(pdfBuf, cb) {
let pdfData;
try {
pdfData = new Uint8Array(pdfBuf);
pdfjs.getDocument(pdfData).then((doc) => {
cb(null, doc);
}).catch((err) => {
cb(err);
});
} catch (uncaughtErr) {
cb(uncaughtErr);
}
};