Skip to content

Instantly share code, notes, and snippets.

@valterbarros
Created September 22, 2023 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valterbarros/35fe90e7db3525872f329d4988e5ca27 to your computer and use it in GitHub Desktop.
Save valterbarros/35fe90e7db3525872f329d4988e5ca27 to your computer and use it in GitHub Desktop.
get original pdf page size
/** @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