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

Export to PDF with script

New Here ,
Jan 09, 2020 Jan 09, 2020

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.

TOPICS
Scripting
5.2K
Translate
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

Advocate , Jan 09, 2020 Jan 09, 2020

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

...
Translate
Community Expert ,
Jan 09, 2020 Jan 09, 2020

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

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PDFExportPresets.html#d1e326997__d1e32704...

 

-Manan

Translate
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
Advocate ,
Jan 09, 2020 Jan 09, 2020

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

Translate
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
New Here ,
Jan 09, 2020 Jan 09, 2020

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.

Translate
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
Advocate ,
Jan 09, 2020 Jan 09, 2020

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

Translate
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 ,
Jan 09, 2020 Jan 09, 2020
LATEST

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

Translate
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