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

Import preset name changing in indesign server instance.

New Here ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Hey,

I am trying to import the PdfPreset as below 

 

app.importFile(ExportPresetFormat.pdfExportPresetsFormat, myFile);

 

and then trying to access the preset last element as such

 

app.pdfExportPresets.lastItem()

 

and then trying to export it to a new PDF

 

myDoc.exportFile(ExportFormat.PDF_TYPE, File(finalPDFDocPath), myPDFexportPreset);

 

But the export file is sometimes failing with the below errorScreenshot 2021-06-30 at 7.55.13 AM.png
And also upon debugging the script there is a numeric value appending to my variable myPDFexportPreset.name, Can someone help me in this regard.
TOPICS
Scripting

Views

444

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 ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

exportFile's third argument is the Showing Options boolean; the preset is the fourth. Add false, before myPDFexportPreset? (Sorry can't change below, on mobile). 

 

Don't know what to say about the number unless you have another preset already named that. 

 

myDoc.exportFile(ExportFormat.PDF_TYPE, File(finalPDFDocPath), myPDFexportPreset);

 

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

app.importFile()

is used to import a file into InDesign. You shouldn't import a PDF preset.

You get a handle on a particular preset using e.g.

myPreset = app.pdfExportPresets.item('[Smallest File Size]');

or any other name. Using lastItem() is unwise because you can't really ever be sure what the last preset is.

 

The debugging error is probably caused by the fact that InDesign Server's PDF export method uses three parameters whereas InDesign Desktop uses four: Server has no interface so that the parameter that Brian mentioned (true/false, whether to display the export window) is used on Desktop but not on Server. Your script should therefore test whether it runs on Desktop or Server:

if (app.name === 'Adobe InDesign') { // Desktop
   myDoc.exportFile(ExportFormat.PDF_TYPE, File(finalPDFDocPath), false, myPDFexportPreset);
} else {  // Server
   myDoc.exportFile(ExportFormat.PDF_TYPE, File(finalPDFDocPath), myPDFexportPreset);
}

 

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
Guide ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

> app.importFile  … You shouldn't import a PDF preset

 

Peter, are you sure?

https://www.indesignjs.de/extendscriptAPI/indesign16/#Application.html#d1e42253__d1e47259

The API lists exactly these preset formats.

It is unfortunate that the importFile method does not return the imported object.

Using the last item is IMO a good guess – if it works. Otherwise I'd remember the known specifiers before import and use the newly added.

 

Also, I would recommend to not hard wire localized names.

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Well, what do you know. You can indeed import export preferences according to the OMV. It just seems counterintuitive to place an export preference in an InDesign document. Why would you want to do that? And there's no need to do so if you want to use a preset to export a document.

 

> Also, I would recommend to not hard wire localized names.

 

Absolutely. I just gave that example to show how to use a preset's name.

 

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Hi Peter,

I have no InDesign Server at hand, but according to DOM documentation for InDesign Server CS6, see the chm files at:

http://www.jongware.com/idjshelp.html

this line should work:

app.importFile( ExportPresetFormat.PDF_EXPORT_PRESETS_FORMAT , pdfExportPresetFile );

Provided of course that the preset file, a valid *.joboptions file, exists.

 

From the InDesign Server CS6 chm file DOM documentation:

app.importFile()-method-InDesignServerCS6-DOM-Docu.PNG

 

ExportPresetFormats-InDesignServerCS6-DOM-Docu.PNG

 

Tested this with my desktop version of InDesign 2021 and it's working very well.

Duplicated a joboptions file to my desktop, renamed it and successfully imported it to InDesign with:

 

$.writeln( app.pdfExportPresets.everyItem().getElements().length );
// 54

var presetFile = File( "~/Desktop/MyNewPDFExportPreset.joboptions" );

if( presetFile.exists )
{
	app.importFile
	( 
		ExportPresetFormat.PDF_EXPORT_PRESETS_FORMAT , 
		presetFile
	);
};

$.writeln( app.pdfExportPresets.everyItem().getElements().length );
// 55

 

Result with my German InDesign 2021:

 

pdfExportPreset-file-loaded.PNG

 

Regards,
Uwe Laubender

( ACP )

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

My points remain: why would you want to do it, and it's not necessary.

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Peter Kahrel said: "My points remain: why would you want to do it…"

If a customer or a printing company provides a *.joboptions file for example.

 

jack55555 said: "I am trying to import the PdfPreset as below"

You do not import a pdf preset, you do import a pdf export preset file with method app.importFile().

 

That must be a valid *.joboptions file.

Something like that:

 

joboptions-file-opened-in-Editor.PNG

 

Regards,
Uwe Laubender

( ACP )

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

@Laubender 

So you mean that when you import a PDF preset, it's placed in the correct directory?

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Well, yes. At least that should happen if IT did not block anything.

The *.joboptions file will be duplicated to the Settings directory on Windows 10:

[Username] > AppData > Roaming > Adobe > Adobe PDF > Settings

 

DuplicateOfJoboptionsFile-in-Settings.PNG

On Mac OS this should work the same. However with newer Mac OS versions there could be a difference according to the preset safety policies perhaps.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Ok, thanks, Uwe. Now I understand the import, and the choice of lastItem(). But still, lastItem() seems dodgy. Better use the name obtained from myFile, which was used in the import command.

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
Guide ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

There is already an old version of preset "Test". Rather than replacing it, InDesign renamed your shiny new import, it appended a number suffix "Test 27". So you better clean up your preset after use.

If you just go by the name, you'd end up using that initial version of "Test" that Dave installed at the server 10 years ago.

If you remove the collision before import, you might cause a concurrency problem with other jobs running on the same machine. Actually you still have a concurrency problem, because you never know whether lastItem() is yours or one imported by another job running at the same time.

To avoid that, use a maintenance time slot (when no regular jobs are running) to install job options.

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
New Here ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

I have files preset files that are being added into the adobe PDF > settings folder, But I have the same preset file which is being imported from different locations which are creating multiple files in the settings folder with a different suffix( which is correct) but the export PDF itself is very inconsistent and it throws "failed to export the PDF file"( using the code below)

myDoc.exportFile(ExportFormat.PDF_TYPE, File(finalPDFDocPath), myPDFexportPreset);

  Also, I would like to know when exactly the preset files will be removed from the adobe PDF > settings folder?

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Hi Dirk,

perhaps it would help to rename the *.joboptions file before import with a unique file name.

So that the name can be identified by app.pdfExportPresets[n].name if it is unclear if app.pdfExportPresets[-1] represents the property/value pairs of the last imported pdfExportPreset *.joboptions file as far as InDesign is able to read and understand them.

 

Regards,
Uwe Laubender

( ACP )

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
Guide ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

Hi Uwe,

yes that would be a good idea. On the other hand I haven't checked whether InDesign Server already uses different folders as sandbox per instance or configuration. Leaving some homework for the OP ...

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 ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

LATEST

"But I have the same preset file which is being imported from different locations"

 

Hi Jack,

before you import a pdf export preset file, test if a file is already there with the same or a similar name.

pdfExportPresets[n].fullName gives you the file of an installed pdf export preset.

When in doubt import the new preset file and compare all relevant property/value pairs with a previous pdfExportPreset.

 

Regards,
Uwe Laubender

( ACP )

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