Skip to content

Method to get pageNumber for TextFields in pdf-lib ?? #1493

Closed Answered by satyajitnayk
satyajitnayk asked this question in Q&A
Discussion options

You must be logged in to vote

Method to give page number map as of current code structure of pdf-lib:

async function getPageNumberMapForFields(pdfDoc: PDFDocument) {
    const d: { [key: string]: number } = {};
    const form = pdfDoc.getForm();
    const pages = pdfDoc.getPages();
    form.getFields().forEach((field) => {
      form
        .getField(field.getName())
        .acroField.getWidgets()
        .forEach((w) => {
          const widgetRef: PDFRef | undefined = pdfDoc.context.getObjectRef(
            w.dict,
          );
          for (let idx = 0, len = pages.length; idx < len; idx++) {
            if (
              pages[idx].node.Annots()?.indexOf(widgetRef as PDFRef) !==
              undefined

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by satyajitnayk
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant