i'm using pdfjsLib to check the data of my pdf.
After 3 days i'm still stuck...
I can find text inside my pdf but i don't know how to check if my PDF contain and image or not.Any ideas ?
here a sample of my code (stackItem == url of pdf file)
const loadingTask = pdfjsLib.getDocument(stackItem);
loadingTask.promise
.then(function (doc: { numPages: any; getMetadata: () => Promise<any>; getPage: (arg0: any) => Promise<any>; }) {
const numPages = doc.numPages;
console.log("# Document Loaded");
console.log("Number of Pages: " + numPages);
console.log();
let lastPromise;
lastPromise = doc.getMetadata().then(function (data: { info: any; metadata: { getAll: () => any; }; }) {
console.log("# Metadata Is Loaded");
console.log("## Info");
console.log(JSON.stringify(data.info, null, 2));
if (data.metadata) {
console.log("## Metadata");
console.log(JSON.stringify(data.metadata.getAll()),);
}
});
const loadPage = function (pageNum: string) {
return doc.getPage(pageNum).then(function (page: { getViewport: (arg0: { scale: number; }) => any; getTextContent: () => Promise<any>; cleanup: () => void; }) {
console.log("# Page " + pageNum);
const viewport = page.getViewport({ scale: 1.0 });
console.log("Size: " + viewport.width + "x" + viewport.height);
console.log();
return page
.getTextContent()
.then(function (content: { items: any[]; }) {
const strings = content.items.map(function (item: { str: any; }) {
return item.str;
});
console.log("## Text Content");
console.log(strings.join(" "));
page.cleanup();
})
.then(function () {
console.log();
});
});
};
// Loading of the first page will wait on metadata and subsequent loadings
// will wait on the previous pages.
for (let i = 1; i <= numPages; i++) {
lastPromise = lastPromise.then(loadPage.bind(null, i));
}
return lastPromise;
})
.then(
function () {
console.log("# End of Document");
},
function (err: string) {
console.error("Error: " + err);
}
);
thx