Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I believe this one:
var myTrustedExportDataObject = app.trustedFunction(function (doc, vName) { app.beginPriv(); myExportDataObject(doc, vName); app.endPriv(); });
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more