Hi,
I'm wanting to load a PDF and read out the size of the first page. Is this possible using pdf-lib?
Thanks
Yes, pdf-lib can do this. However, the API for it is not currently documented. But I have explained how to do it here: https://github.com/Hopding/pdf-lib/issues/10#issuecomment-402326518. For example:
const pages = pdfDoc.getPages();
const page1 = pages[0];
const PAGE_WIDTH = page1.get('MediaBox').array[2];
const PAGE_HEIGHT = page1.get('MediaBox').array[3];
Please let me know if you have any trouble with this.
UPDATE: Please use the getPageDimensions() function defined here to obtain the width and/or height of a page. The page1.get('MediaBox').array[...]; calls used here do not work on all documents.
Most helpful comment
Yes,
pdf-libcan do this. However, the API for it is not currently documented. But I have explained how to do it here: https://github.com/Hopding/pdf-lib/issues/10#issuecomment-402326518. For example:Please let me know if you have any trouble with this.
UPDATE: Please use the
getPageDimensions()function defined here to obtain the width and/or height of a page. Thepage1.get('MediaBox').array[...];calls used here do not work on all documents.