Pdf-lib: Is it possible to get the size of an existing page?

Created on 9 Oct 2018  路  1Comment  路  Source: Hopding/pdf-lib

Hi,
I'm wanting to load a PDF and read out the size of the first page. Is this possible using pdf-lib?

Thanks

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

faxemaxee picture faxemaxee  路  6Comments

AlanHadzic picture AlanHadzic  路  3Comments

dhollenbeck picture dhollenbeck  路  4Comments

kevinswartz picture kevinswartz  路  8Comments

MarcGodard picture MarcGodard  路  3Comments