Copy link to clipboard
Copied
Can someone please point me to the explanation/documentation on how to export to PDF by skript? I'm especially interested in:
- How do I set the filenames/pathes.
- How do I manipulate the PDF-settings from skript.
I'm pretty sure this is documented somewhere, but I couldn't find it.
Thanks a lot.
Hi @Lordrhavin , Rather than use new PDFExportPreset(), try app.pdfExportPresets.add()—if you use new PDFExportPreset(), then the exportFile() parameter should be myPDFExportPreset.name.
But you want to watch out for adding a new, unnamed preset everytime you run the script, or you’ll get this:
I use something like this to create new or temporary presets:
var doc = app.activeDocument;
if (doc.saved) {
var fp = doc.filePath + "/" + doc.name.replace(/\.[^\.]+$/, '') + ".pdf"
Copy link to clipboard
Copied
.
Copy link to clipboard
Copied
That is a nice start, but not a documentation.
app.pdfExportPreset: how do I create a new one, it has no contructor. I dont want a preset-selection-dialog, i want to construct a new app.pdfExportPreset and set the appropriate settings. is the source-code of this java-class somewhere to be found? I found this one:
https://developer.adobe.com/indesign/dom/api/p/PDFExportPreset/
But is is not really helpful, as it doesnt state a c-tor or any factory method.
Copy link to clipboard
Copied
First, you need to create PDFExportPreset - if you don't want to use existing one:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PDFExportPreset.html
Then set PDFExportPreference:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PDFExportPreference.html#d1e324759
or InteractivePDFExportPreference:
Then use it when exporting Document:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49551__d1e53952
Or just use Google...
Copy link to clipboard
Copied
This is a pretty good page. It should be pinned here somewhere.
Copy link to clipboard
Copied
According to this:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49551__d1e53952
exportFile () expects an PDFExportPreset-object. What is the difference to an PDFExportPreference (they look like having mostly the same settings) and what do I need it for in this case?
Copy link to clipboard
Copied
According to this:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49551__d1e53952
exportFile () expects an PDFExportPreset-object. What is the difference to an PDFExportPreference (they look like having mostly the same settings) and what do I need it for in this case?
By @Lordrhavin
They are SIMILAR but not EACTLY the same.
You use PRESET - "template" - to define and then load "general" settings - but you change PREFERENCEs just before you execute Export.
For example, you need to set pageRange in the Preferences - it's not present in the Preset.
Copy link to clipboard
Copied
What is the difference to an PDFExportPreference
Also, you might not really need to create a new or temporary preset. I can simplify my example by using the default PDF/X-4 preset for the export preset parameter, and use pdfExportPreferences for the changes:
var doc = app.activeDocument;
if (doc.saved) {
var fp = doc.filePath + "/" + doc.name.replace(/\.[^\.]+$/, '') + ".pdf"
var preset = app.pdfExportPresets.itemByName("[PDF/X-4:2008]")
//make changes to the chosen preset’s export without altering the preset itself
app.pdfExportPreferences.properties={pageRange:"1", exportLayers:true, exportNonprintingObjects:true, exportWhichLayers:ExportLayerOptions.EXPORT_VISIBLE_LAYERS, generateThumbnails:true, pdfDisplayTitle:PdfDisplayTitleOptions.DISPLAY_DOCUMENT_TITLE}
//export
doc.exportFile(ExportFormat.pdfType, File(fp), false, preset);
} else {
alert("Document Not Saved")
}
Copy link to clipboard
Copied
@Robert at ID-Tasker @Anantha Prabu G
The following code spaws the following error at the exportFile()-command (translation from German, might not be exact:
"invalid value for parameter using, PDFExportPreset expected but nothig gotten."
I'm not sure how this can happen, as the using-parameter (the 4th one) *is* a PDFExportPreset-object in my code. anyone can chime in an explain this error?
function main() {
var name = app.activeDocument.name;
name = name.replace (/\.(indd|indt|idml)$/, ".pdf")
var path = null;
try {
path = app.activeDocument.filePath;
} catch (error) {} // we ignore if file is unsaved.
path = Folder(path).selectDlg ('Select folder for the exported PDFs:');
if (path === null) // user clicked cancel
return false;
var myPDFExportPreset = new PDFExportPreset();
myPDFExportPreset.acrobatCompatibility = AcrobatCompatibility.ACROBAT_6;
myPDFExportPreset.exportLayers = true;
myPDFExportPreset.exportNonprintingObjects = true;
myPDFExportPreset.exportWhichLayers = ExportLayerOptions.EXPORT_VISIBLE_LAYERS;
myPDFExportPreset.generateThumbnails = true;
myPDFExportPreset.pdfDisplayTitle = PdfDisplayTitleOptions.DISPLAY_DOCUMENT_TITLE;
app.activeDocument.exportFile(ExportFormat.pdfType, File(path + "/" + name), false, myPDFExportPreset);
return true;
}
app.doScript(main,ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'Export-Test');
Copy link to clipboard
Copied
Hi @Lordrhavin , Rather than use new PDFExportPreset(), try app.pdfExportPresets.add()—if you use new PDFExportPreset(), then the exportFile() parameter should be myPDFExportPreset.name.
But you want to watch out for adding a new, unnamed preset everytime you run the script, or you’ll get this:
I use something like this to create new or temporary presets:
var doc = app.activeDocument;
if (doc.saved) {
var fp = doc.filePath + "/" + doc.name.replace(/\.[^\.]+$/, '') + ".pdf"
//make a temporary preset from the default PDF/X-4 preset
var preset = makePDFPreset("TempPDF", app.pdfExportPresets.itemByName("[PDF/X-4:2008]"));
//adjusted properties
preset.properties = {exportLayers:true, exportNonprintingObjects:true, exportWhichLayers:ExportLayerOptions.EXPORT_VISIBLE_LAYERS, generateThumbnails:true, pdfDisplayTitle:PdfDisplayTitleOptions.DISPLAY_DOCUMENT_TITLE}
//export
doc.exportFile(ExportFormat.pdfType, File(fp), false, preset);
//remove the created preset after export?
preset.remove()
} else {
alert("Document Not Saved")
}
/**
* Gets an existing PDF preset, or makes a new named PDF Preset based on an existing preset
* @ param the preset name
* @ param bo, an existing preset
* @ return the pdf preset
*/
function makePDFPreset(n, bo){
var ps = app.pdfExportPresets.itemByName(n);
if (ps.isValid) {
return ps;
} else {
ps = app.pdfExportPresets.add({name:n});
ps.properties = bo.properties;
return ps;
}
}
Copy link to clipboard
Copied
@rob day :
Interestingly, as I have just discovered, these unnamed new presets will appear in the menu but NOT in the Define Adobe PDF Presets window (at least when created by AppleScript). And if you open the Define... window, then click Done to exit, these unnamed presets will be deleted.
Just an observation...
Copy link to clipboard
Copied
Hi @leo.r , I see the same with this AS, but it does not happen with ExtendScript.
tell application id "com.adobe.indesign"
set myPDFExportPreset to make PDF export preset
end tell
Maybe because AS doesn’t have the add method?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Please replace this line
var myPDFExportPreset = new PDFExportPreset();
to
var myPDFExportPreset = app.pdfExportPresets.add();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now