• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

[JS] How do you set preferences for Interactive PDF export?

Explorer ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

I am trying to export an Interactive PDF document with certain compression settings using a script. If I manually export it and set the compression settings to the following:

  • Compression - > Automatic
  • JPEG Quality - > Maximum
  • Resolution (ppi) - > 72

The images in the document come out with perfect detail. 

If on the other hand I try to export the Interactive PDF document via my script the images in the document come out blurry. I am setting the three settings above in my script but they seem to have no effect. 

Here is my code:

openFile = File(myFolder + docToProcess);
saveFile = File(myFolder + docToProcess.substring(0,docToProcess.length - 4) + ".pdf")
var docFile = app.open(openFile, Boolean.true, OpenOptions.OPEN_ORIGINAL);
var gDoc = app.activeDocument;

with (app.interactivePDFExportPreferences) {
	pdfRasterCompression = PDFRasterCompressionOptions.AUTOMATIC_COMPRESSION;	
	pdfJPEGQuality = PDFJPEGQualityOptions.MAXIMUM;
	pageRange = PageRange.ALL_PAGES;
	rasterResolution = RasterResolutionOptions.SEVENTY_TWO_PPI;
}

gDoc.exportFile(ExportFormat.INTERACTIVE_PDF, saveFile, Boolean.true);
docFile.close(SaveOptions.NO);

The weird thing is if I try to export the document manually after running the script I can see that the script has changed the "Compression" settings for Interactive PDF export dialogue. So it looks like my script is changing the preferences but those preferences are having no impact on the actual exported PDF. Am I doing anything wrong here or missing anything?

 

As an aside, setting the third parameter in the gDoc.exportFile command to true should show the options dialogue shouldn't it? Here is what it says in the reference, "If true, displays the export options dialog.". InDesign ExtendScript API (16.0) 

At the begining of my script I also have the following: 

app.scriptingPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

My understanding is that the true option in the exportFile command and the scriptPreferences should allow the options dialogue to pop up when exporting the PDF in the script. When I run the script it just exports the PDF with no dialogue opening. Why is the dialogue not opening? Ideally, I would like to just export it without user interaction but I am trying all kinds of different options to debug this problem.

 

I am running the script via the ExtendScript Debugger 2.0 Beta 3.0 Release on Visual Studio Code.

 

Thank you in advance for any help provided.

TOPICS
Scripting

Views

822

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 2 Correct answers

Community Expert , Mar 29, 2022 Mar 29, 2022

Try not using 'with'. It doesn't always behave as expected. So something like this:

 

app.interactivePDFExportPreferences.properties = {
  pdfRasterCompression: PDFRasterCompressionOptions.AUTOMATIC_COMPRESSION,
  pdfJPEGQuality: PDFJPEGQualityOptions.MAXIMUM,
  pageRange: PageRange.ALL_PAGES,
  rasterResolution: RasterResolutionOptions.SEVENTY_TWO_PPI,
}

and if that doesn't work, try this:

app.interactivePDFExportPreferences.pdfRasterCompression = PDFRasterCompressionOptions.AUTOMATIC_COMPRESSI
...

Votes

Translate

Translate
Explorer , Mar 29, 2022 Mar 29, 2022

Hi Peter,

 

I tried both of those options and I got the same results i.e. blurry image. Your suggestions helped though in that it helped me eliminate the code as causing the problem and to try and look elsewhere for the problem.

 

I did some more experimenting and I think I have finally figured it out. I originally transfered these files from the network. Since I was running them locally I decided to copy the images locally and relink them. I also embedded the images in the file (in the link panel).

...

Votes

Translate

Translate
Community Expert ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Hi @JO_15, here is an example that I use to export a particular project. Maybe the differences will help you.

- Mark

with (app.interactivePDFExportPreferences) {
    exportAsSinglePages = false;
    exportLayers = false;
    exportReaderSpreads = false;
    flipPages = false;
    generateThumbnails = false;
    includeStructure = false;
    interactivePDFInteractiveElementsOption = InteractivePDFInteractiveElementsOptions.INCLUDE_ALL_MEDIA;
    openInFullScreen = false;
    pageRange = PageRange.ALL_PAGES;
    pageTransitionOverride = PageTransitionOverrideOptions.NONE;
    pdfDisplayTitle = PdfDisplayTitleOptions.DISPLAY_FILE_NAME;
    pdfJPEGQuality = PDFJPEGQualityOptions.MEDIUM;
    pdfMagnification = PdfMagnificationOptions.FIT_PAGE;
    pdfPageLayout = PageLayoutOptions.SINGLE_PAGE;
    pdfRasterCompression = PDFRasterCompressionOptions.JPEG_COMPRESSION;
    rasterResolution = 225;
    viewPDF = false;
}

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
Explorer ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

Thank you Mark. I gave it a try using your exact settings and the images were still blurry. I also tried using your exact settings but changing PDFJPEGQualityOptions.MEDIUM to PDFJPEGQualityOptions.MAXIMUM and had the same result. Your code still helped me understand that I am setting the export preferences correctly in my code. So maybe there is something else somewhere that is interfering with the setting of the preferences in my script??? The weird thing is that when I manually open the document to export it all the preference that were set in the code are now set in the preference dialgue. For example my raster resolution was 72 but when I ran your code it got changed to 225. 

 

I think I am going to go bald from pulling my hair out on this one lol. There has to be some reason this is not working but I cannot figure out what it is.

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 ,
Mar 29, 2022 Mar 29, 2022

Copy link to clipboard

Copied

Try not using 'with'. It doesn't always behave as expected. So something like this:

 

app.interactivePDFExportPreferences.properties = {
  pdfRasterCompression: PDFRasterCompressionOptions.AUTOMATIC_COMPRESSION,
  pdfJPEGQuality: PDFJPEGQualityOptions.MAXIMUM,
  pageRange: PageRange.ALL_PAGES,
  rasterResolution: RasterResolutionOptions.SEVENTY_TWO_PPI,
}

and if that doesn't work, try this:

app.interactivePDFExportPreferences.pdfRasterCompression = PDFRasterCompressionOptions.AUTOMATIC_COMPRESSION;	
app.interactivePDFExportPreferences.pdfJPEGQuality = PDFJPEGQualityOptions.MAXIMUM;
app.interactivePDFExportPreferences.pageRange = PageRange.ALL_PAGES;
app.interactivePDFExportPreferences.rasterResolution = RasterResolutionOptions.SEVENTY_TWO_PPI;

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
Explorer ,
Mar 29, 2022 Mar 29, 2022

Copy link to clipboard

Copied

Hi Peter,

 

I tried both of those options and I got the same results i.e. blurry image. Your suggestions helped though in that it helped me eliminate the code as causing the problem and to try and look elsewhere for the problem.

 

I did some more experimenting and I think I have finally figured it out. I originally transfered these files from the network. Since I was running them locally I decided to copy the images locally and relink them. I also embedded the images in the file (in the link panel). After that the code you listed above successfully exports the PDF and the images look how they should.

 

What I don't understand is why it worked manually but would not work via the script originally. I would have thought it would not work manually. Regardless it seems to be working now. Thank you to you and m1b for the help!

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 ,
Mar 29, 2022 Mar 29, 2022

Copy link to clipboard

Copied

LATEST

Hi @JO_15, when you troubleshoot problems like this, it is important to only change one thing at a time. As it stands you can't know which of the things you changed actually solved the problem. It sounds a bit like it wasn't anything to do with the script in any case, although you have learned some things (as have I) about scripting the pdf export, so that's good at least.

- Mark

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