Skip to main content
Ryan_Oliver_02445
Known Participant
January 23, 2019
Answered

How to export document as FDF, then import said file back into document?

  • January 23, 2019
  • 1 reply
  • 1258 views

Good evening, I am trying to create a program which will export the PDF document as a FDF file, add pages, then import the FDF file back into itself.

Here is my code, as a javascript action in adobe:

var Pgx = ("G:\Team Drives\GENETICS\LOGISTICS\REC FORMS\REC FORM SHORTCUT\1-LS PGX REC FORM.pdf");

var Cgx = ("G:\Team Drives\GENETICS\LOGISTICS\REC FORMS\REC FORM SHORTCUT\2-MHS CGX REC FORM.pdf");

var File = (this.documentFileName.replace(/.pdf/,""));

this.exportAsFDF({cPath: File(".fdf")});

this.insertPages({cPath: Pgx});

this.insertPages({cPath: Cgx});

this.importAnFDF({cPath: File(".fdf")});

I have tried looking up for what I could find on the forums, and internet, but it seems that my program does not want to add pages, OR export/import FDf files.  Any help would be appreciated!  I apologize for my lack of coding skill with Java/Javascript.

This topic has been closed for replies.
Correct answer try67

There are multiple errors in this code... Try this instead:

var fdfFilePath = this.path.replace(".pdf",".fdf"));

var pgxFilePath = "/G/Team Drives/GENETICS/LOGISTICS/REC FORMS/REC FORM SHORTCUT/1-LS PGX REC FORM.pdf";

var cgxFilePath = "/G/Team Drives/GENETICS/LOGISTICS/REC FORMS/REC FORM SHORTCUT/2-MHS CGX REC FORM.pdf";

this.exportAsFDF({cPath: fdfFilePath});

this.insertPages({cPath: pgxFilePath});

this.insertPages({cPath: cgxFilePath});

this.importAnFDF({cPath: fdfFilePath});

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 23, 2019

There are multiple errors in this code... Try this instead:

var fdfFilePath = this.path.replace(".pdf",".fdf"));

var pgxFilePath = "/G/Team Drives/GENETICS/LOGISTICS/REC FORMS/REC FORM SHORTCUT/1-LS PGX REC FORM.pdf";

var cgxFilePath = "/G/Team Drives/GENETICS/LOGISTICS/REC FORMS/REC FORM SHORTCUT/2-MHS CGX REC FORM.pdf";

this.exportAsFDF({cPath: fdfFilePath});

this.insertPages({cPath: pgxFilePath});

this.insertPages({cPath: cgxFilePath});

this.importAnFDF({cPath: fdfFilePath});

Ryan_Oliver_02445
Known Participant
January 23, 2019

Amazing, it works like a charm, I noticed the backwards slashes after a created my post... though I do have a question, however:

Is there a way to have the pages being imported, to be imported after the last page? 

try67
Community Expert
Community Expert
January 23, 2019

Yes. Change these lines:

this.insertPages({cPath: pgxFilePath}); 

this.insertPages({cPath: cgxFilePath}); 

To:

this.insertPages({cPath: pgxFilePath, nPage: this.numPages-1}); 

this.insertPages({cPath: cgxFilePath, nPage: this.numPages-1}); 

All of this is documented in the Acrobat JavaScript API Reference, which you should really use if you want to write scripts for Acrobat...