Search code examples
pdfacrobat

Acrobat DC preflight processes non-PDF files


I want to process and verify that PDFs within a folder are valid PDF/A files. The problem is that I need to process a folder with piles of files including word and excel among others that preflight converts to PDFs, processes, and then hangs for user input to discard the temperary file. There are some hundred files, so waiting for user input isn't doable.

Perhaps I'm not using the correct phrases when I search, but I can't find out how to force Adobe Acrobat DC to only process PDF files. I've found that in Acrobat X you can specify source files https://www.evermap.com/ActionWizardX.asp, but I've not found an equivalent in DC.

Is there a way to force an action to only process PDF files?


Edit:

Following @Joel Geraci's suggestion and finding this post, I've created the following script that runs in an action. At this point, It seems to run the profile, but I don't know if it actually modifies the document, since the call to this.closeDoc() doesn't prompt to save the document, and the resulting document doesn't seem to be saved as a PDF/A file.

/* Convert PDF/A-3a */
try
{
  if(this.path.split('.').pop() === 'pdf')
  {
    var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");

    if( oProfile != undefined )
    {
      var myPreflightResult = this.preflight( oProfile);
      console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
      console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
      console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
      console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
      console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
      this.closeDoc();
    }
  }
}
catch(theError)
{
  $error = theError;
  this.closeDoc( {bNoSave : true} );
}

Edit 2:

I ended up settling on using the saveAs function. I'm not sure how to export the XML data to a file, but this seems to be sufficient.

/* Convert PDF/A-3a */
try
{
  if(this.path.split('.').pop() === 'pdf')
  {
    var oThermometer = app.thermometer;
    var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");

    if( oProfile != undefined )
    {
      var myPreflightResult = this.preflight( oProfile, false, oThermometer );
      console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
      console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
      console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
      console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
      console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
      if(myPreflightResult.numErrors > 0) {
        var cXMLData = myPreflightResult.report(oThermometer);
        console.println(cXMLData);
      }
      this.saveAs(path,"com.callas.preflight.pdfa");
    }
  }
}
catch(theError)
{
  $error = theError;
  this.closeDoc( {bNoSave : true} );
}

Edit 3:

So the problem is that non-PDF files are converted and read before my JavaScript is executed, which means that the this.path.split('.').pop() === 'pdf' doesn't actually filter out anything. I found that the requiresFullSave property of the Doc class specifies whether the document is a temp file or not. I have, however, found that I am still asked if I want to save the temp file, which doesn't help.

Edit 4

Calling Doc.closeDoc(true) on a temporary file causes Acrobat to crash and there doesn't seem to be another way to close a document without saving. I've found there is no clear way (that I've found) to close a temp document without prompting the user to save and have resorted to deleting all non-PDF files.

Final script:

/* Convert PDF/A-3a */
try
{
  console.println(path + " is temp: " + requiresFullSave);
  if(!requiresFullSave)
  {
    var oThermometer = app.thermometer;
    var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");

    if( oProfile != undefined )
    {
      var myPreflightResult = this.preflight( oProfile, false, oThermometer );
      console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
      console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
      console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
      console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
      console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
      if(myPreflightResult.numErrors > 0) {
        var cXMLData = myPreflightResult.report(oThermometer);
        console.println(cXMLData);
      }
      this.saveAs(path,"com.callas.preflight.pdfa");
    }
  }
  else{
    // As noted in the documentation found [here][2]
    // Note:If the document is temporary or newly created, setting dirty to false has no effect. That is, the user is still asked to save changes before closing the document. See requiresFullSave.
    // this.dirty = false; 
    // this.closeDoc(true);
  }
}
catch(theError)
{
}

Solution

  • Rather than creating an action that runs preflight, try creating an action that runs some JavaScript. The JavaScript would test for the file extension of the file being processed and then execute preflight via JavaScript if it's a PDF, skipping it if not.