diff --git a/lib/index.js b/lib/index.js index 48939c5..c967bc1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -76,9 +76,23 @@ class PDFExtract { const firstPage = (options && options.firstPage) ? options.firstPage : 1; const lastPage = Math.min((options && options.lastPage) ? options.lastPage : doc.numPages, doc.numPages); pdf.pdfInfo = doc.pdfInfo; + + pdf.attachments = []; const promises = [ doc.getMetadata().then(data => { pdf.meta = {info: data.info, metadata: data.metadata ? data.metadata.getAll() || null : null}; + }), + doc.getAttachments().then(attachments => { + if (attachments) { + for (const attachment of Object.entries(attachments) ) { + pdf.attachments.push({ + filename: attachment[0], + data: attachment[1].content + }); + } + } + }).catch(error => { + console.log(`Failed to extract attachments from PDF: ${error}`); }) ]; const loadPage = pageNum => doc.getPage(pageNum).then(page => {