Created
September 22, 2023 18:16
-
-
Save valterbarros/35fe90e7db3525872f329d4988e5ca27 to your computer and use it in GitHub Desktop.
get original pdf page size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @typedef {import("pdfjs-dist/lib/display/api.js").PDFDocumentProxy} PDFDocumentProxy */ | |
/** | |
* @param {String} pdfUrl | |
* @param {PDFDocumentProxy} documentProxy - pdf.js document proxy object | |
*/ | |
const handleGetPageSize = async ({ pdfUrl, documentProxy }) => { | |
const documentKey = archives.value.find((archive) => archive.documentPdfUrl === pdfUrl).key; | |
const pageBaseList = Array.from({ length: documentProxy.numPages }); | |
const pageOriginalSizePromise = pageBaseList.map(async (_item, index) => { | |
const page = await documentProxy.getPage(index + 1); | |
const [, , width, height] = page.view; | |
return { [documentKey]: { [index + 1]: [width, height] } }; | |
}); | |
const pageOriginalSize = await Promise.all(pageOriginalSizePromise); | |
const mergedKeys = merge(...pageOriginalSize); | |
originalPageSizes.value = { ...originalPageSizes.value, ...mergedKeys }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment