Skip to main content
Inspiring
August 7, 2023
Question

Export specific number of pages into XFDF

  • August 7, 2023
  • 3 replies
  • 583 views

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
}

--------------------------------
 
This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
August 7, 2023

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.

try67
Community Expert
Community Expert
August 7, 2023

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.

Bernd Alheit
Community Expert
Community Expert
August 7, 2023

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

KaxkulAuthor
Inspiring
August 7, 2023

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.

BarlaeDC
Community Expert
Community Expert
August 7, 2023

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.