Skip to main content
Participant
May 22, 2018
Question

Flatten pages using Javascript

  • May 22, 2018
  • 1 reply
  • 3710 views

I am using a Javascript to fills and save forms from data in a text file (Import.txt). I have managed to save the docs and give them file names using form data. I also save them as pdf/a. But I would also like them flattened. Where and how do I use the this.flattenpages-function?

Here is my script

var fileName = "/Users/admin/Desktop/Create/import.txt";

var outputDir = "/Users/admin/Desktop/Create/";

var err = 0;

var idx = 0;

while (err == 0) {

  err = this.importTextData(fileName, idx); // imports the next record

  if (err == -1)

  app.alert("Error: Cannot Open File");

  else if (err == -2)

  app.alert("Error: Cannot Load Data");

    else if (err == 1)

        app.alert("Warning: Missing Data");

    else if (err == 2)

        app.alert("Warning: User Cancelled Row Select");

    else if (err == 3)

        app.alert("Warning: User Cancelled File Select");

  else if (err == 0) {

        this.flattenpages(); // where does this go?

  this.saveAs(outputDir +”Document_”+ this.getField("Orgnr2").value + ".pdf","com.callas.preflight.pdfa"); // saves the file

  idx++;

  }

}

This topic has been closed for replies.

1 reply

Inspiring
May 22, 2018

The Acrobat JavaScript Reference for flattenPages has a working example of the code for an entire PDF.