Skip to main content
Participant
July 19, 2024
Question

JavaScript how Export PDF data to the open file directory?

  • July 19, 2024
  • 1 reply
  • 1472 views

Hi guys,

I'm learning JavaScript for Adobe Acrobat Pro, I have a script that:

 

When the "export" button is hit, a window to browse/save the file is open.

The directory shown by default is not the same as the open PDF.


I'm struggling to find a way for the script to use the open PDF directory to be displayed by default when I hit "export". I'll be working with many different subfolders and it can be really risky if I accidentally save the file on the wrong folder.

The script has the standard recommendation code for security etc, but let me know if I could be missing something. I'm sorry but I'm not allowed to share the code.

Is it even possible? 

Thank you

This topic has been closed for replies.

1 reply

PDF Automation Station
Community Expert
Community Expert
July 19, 2024

Are you exporting data or saving the PDF?  It's pretty hard to help when you won't share your code.  You don't have to show anything in the code that will identify paths, companies, individuals, etc.   Saving silently with a folder level script can avoid saving to the wrong directory.  You can pull the directory path from current document using this.path.

GL11558Author
Participant
July 19, 2024

Hello, saving silently is a good idea/turnaround, thank you! But the issue is sometimes I would need to change to a different folder, so I can't lose this capability. The script also has the import button, which I don't think importing silent would be a practical option as the file names will be changing.

 

The script doesn't change the PDF, only export and import tooltips.
I managed to remove the confidential information:

function exportTooltips() {
var br = "\r\n";
var sep = "\t";

var columns = [
"Object Name",
"Tooltip"
];

var cSummary = columns.join(sep);

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

if (field.userName) {
var tooltipRow = {
"Object Name": field.name.replace(/\s*\(.*?\)\s*/g, ''),
"Tooltip": field.userName
};

var tooltipRowString = columns.map(function (column) {
return escapeTSV(tooltipRow[column] || "");
}).join(sep);

cSummary += br + tooltipRowString;
}
}

var outputFileName = this.documentFileName.replace(/\.pdf$/i, "_Tooltips.txt");
var summaryStream = util.streamFromString(cSummary, "utf-8");

this.createDataObject(outputFileName, cSummary);
this.setDataObjectContents(outputFileName, summaryStream);
myTrustedExportDataObject(this, outputFileName);
this.removeDataObject(outputFileName);
app.alert("Done.", 3);
}

Thank you



PDF Automation Station
Community Expert
Community Expert
July 19, 2024

I assume your TrustedExportDataObject function is using exportDataObject method.  I was going to suggest a popup to modify the file name if necessary, then export the data object silently but cDIPath is no longer supported so you can't do this.  You can't control the initial path in the browser window.

 

You could store the tooltips in a hidden field instead and use import/export FDF and retrieve the tooltips from the import of the that field.