Copy link to clipboard
Copied
Hello,
Is it possible to create custom preset while exporting to PDF using Javascript?
I'm creating new object using:
var saveOpts = new PDFExportPreset();
saveOpts.acrobatCompatibility = AcrobatCompatibility.ACROBAT_5;
document.exportFile(ExportFormat.PDF_TYPE, saveName, false, saveOpts);When I'm calling exportFile I'm getting error message: Invalid value for parameter 'using' of method 'exportFile'. Expected PDFExportPreset, but received nothing.
If I call exportFile without saveOpts parameter, export works but PDF is created using currently active present.
What am I missing?
Thank you.
Try to give name of the preset which you have added already, like this:
app.documents[0].exportFile(ExportFormat.PDF_TYPE, File("~/Desktop/test.pdf"), false, "myPreset");
You are getting error because that preset doesn't exists.
Or else if you really want to add every time, you can do it like this :
//////////////////////////////////////////////////////
var saveOpts = app.pdfExportPresets.add();
saveOpts.acrobatCompatibility = AcrobatCompatibility.ACROBAT_5;
app.documents[0].exportFile(ExportF
Copy link to clipboard
Copied
We don't generally use the new syntax to create an object in InDesign scripting. There are collections or some other objects that provide method to add new objects. For ex;- the app object has pdfExportPresets collection that provides an add method to add a preset. Try the following
var saveOpts = app.pdfExportPresets.add()
Have a look at the DOM documentation
-Manan
Copy link to clipboard
Copied
Try to give name of the preset which you have added already, like this:
app.documents[0].exportFile(ExportFormat.PDF_TYPE, File("~/Desktop/test.pdf"), false, "myPreset");
You are getting error because that preset doesn't exists.
Or else if you really want to add every time, you can do it like this :
//////////////////////////////////////////////////////
var saveOpts = app.pdfExportPresets.add();
saveOpts.acrobatCompatibility = AcrobatCompatibility.ACROBAT_5;
app.documents[0].exportFile(ExportFormat.PDF_TYPE, File("~/Desktop/test.pdf"), false, saveOpts);
//////////////////////////////////////////////////////
Best
Sunil
Copy link to clipboard
Copied
I'm sorry, I come from Illustrator scripting, so I'm used to new syntax 🙂
When I call app.pdfExportPresets.add() new preset is created. After successful export I just remove that preset or is there a different alternative?
Thank you.
Copy link to clipboard
Copied
If you already know which preset you want to use just pass the name of your preset, then you don't need to add preset every time.
app.documents[0].exportFile(ExportFormat.PDF_TYPE, File("~/Desktop/test.pdf"), false, "myPreset");
Best
Sunil
Copy link to clipboard
Copied
Hi Tom,
Thats upto you and your code flow. If the code will be run multiple times then i would suggest that you create a preset(either by adding it using code or just importing it into InDesign using the UI interface) and then use it as many times as needed by passing the name of the preset. The other option would be add the preset by code if not already loaded, do your work and delete it. Anything would work. The goal would be not to clutter the preset list with lots of presets with the same settings, it should be just a single preset and if not needed further good to remove it(just for housekeeping purposes)
-Manan
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more