Copy link to clipboard
Copied
Hey everybody,
First post on here. Searched extensively and I couldn't find any answers to this question.
I have a fillable form that I'd like to add a button to that will delete a set of pages. The page numbers on these may change as someone edits the pdf, so I cannot delete them using the deletePages() function. I have tried giving these pages specific labels (which seem like they should stay the same regardless of whether people add or remove pages throughout).
Is there a javascript function to delete pages based on the page label or convert the label to the page number? Or another workaround for this?
Copy link to clipboard
Copied
You can add a (hidden) form field on these pages, then detect their page number and delete the corresponding pages.
Copy link to clipboard
Copied
Ok cool - what's the function to find the page number of a form field?
Copy link to clipboard
Copied
this.getField("FieldName").page
Copy link to clipboard
Copied
The idea of adding fields to the pages is a good one, but I don't understand the original issue, I must say.
Someone editing a page does not affect its number, unless they move it about in the file. Is that issue?
Anyway, to identify a page by its label would require using a for-loop over the entire array of pages, checking the label of each one (using getPageLabel) until a match is found. Then you use that page's number as the input parameter of deletePages.