• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
4

Skripting: how do I export to several pdfs?

Participant ,
Apr 02, 2024 Apr 02, 2024

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.

TOPICS
Scripting

Views

220

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 02, 2024 Apr 02, 2024

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:

 

Screen Shot 6.png

 

 

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"
...

Votes

Translate

Translate
Engaged ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

.

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2024 Apr 02, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

This is a pretty good page. It should be pinned here somewhere.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2024 Apr 02, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

quote

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

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")
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2024 Apr 02, 2024

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');

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

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:

 

Screen Shot 6.png

 

 

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;
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

@rob day :

 

leor_0-1712077322846.png

 

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...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

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?

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

LATEST
quote

Hi @leo.r , I see the same with this AS, but it does not happen with ExtendScript.

 

Maybe because AS doesn’t have the add method?

 

By @rob day

 

Interesting, yes that's probably the reason...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

Please replace this line 
var myPDFExportPreset = new PDFExportPreset();
to
var myPDFExportPreset = app.pdfExportPresets.add();
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines