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

Export specific number of pages into XFDF

Explorer ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

I use the following code to save only page2, page4 and page6 (3 pages in total) into XFDF, but the problem its saving pages from page2 to page6 (6 pages in total), any help please in relation?

Thanks a lot
----------------------------------------
var emptyFields = [];
var selectedPages = [2, 4, 6]; // Specify the page numbers you want to save

for (var i = 0; i < this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));

if (f.type !== "button" && f.required) {
if (f.valueAsString === f.defaultValue) {
emptyFields.push(f.name);
}
}
}

if (emptyFields.length > 0) {
app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
} else {
var newDoc = this.extractPages({
nStart: selectedPages[0] - 1, // Page numbers are 0-based index
nEnd: selectedPages[selectedPages.length - 1] - 1
});
newDoc.exportAsXFDF(); // Export only the selected pages
}

--------------------------------
 
TOPICS
Edit and convert PDFs , How to , JavaScript , PDF , PDF forms

Views

296

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 ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Create a new document from the 3 pages and export the new document.

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
Explorer ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

It doesn't help to offer users the choice to export specific pages (Please select page2, page4 and pageX, etc.) from a multitude of pages. We aim to simplify and restrict the process, avoiding the provision of multiple options.
Thank you.

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 ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Hi,

I am not sure what you are complaining about in your above post, the extractPages method takes a range of pages, so the options Bernd and Try gave and the only options, you can dress it up however you like to the user but in order to export the pages you want into one document you either have to do one of those options.

 

If you want it to be unseen by the user, then trys option to copy the pages to a new document and then export that document.

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 ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Delete the pages you don't want from the file, then export the form data from it.

Alternatively, create a new document and insert the pages you want into it, then export.

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 ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

LATEST

NB. There's a much easier way of doing it. The exportAsXFDF method has an input parameter (aFields) where you can specify which fields to export. You just need to construct a list of all the fields on those pages, and then supply it to this method, and you won't need to extract or delete anything.

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