• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
17

How to delete pages based on page labels rather than page numbers in Javascript?

New Here ,
Jan 31, 2024 Jan 31, 2024

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?

TOPICS
How to , JavaScript , PDF , PDF forms

Views

116

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2024 Feb 01, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

Ok cool - what's the function to find the page number of a form field?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

LATEST

this.getField("FieldName").page

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2024 Feb 01, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines