Skip to main content
Participating Frequently
May 9, 2016
Question

[JS][CC2015] What's a good way to write a "save as intereactive pdf" script?

  • May 9, 2016
  • 3 replies
  • 664 views

Hello!

i'm a beginner at scripting and i'm having a hard time finding clear explanations (jongware is great for the initiated but not me...).

Anyways, i'm trying to make a script that will do the following :

- save the active document as an interactive document

- with some options (magnification, jpeg quality, layout etc.)

On some docs it works well on some others i get the "Data is out of range" error, and i have no idea what to do with this or why it happens =/

I've had hard time is setting the options. the syntax seems complicated to me. maybe thats what's causing the trouble.

But here is the script i have so far. Feel free to correct =/

app.scriptPreferences.version = 11.0

var myDocument = app.activeDocument;

var myFileName;

if (myDocument.modified == false) {

    myFileName = myDocument.fullName + "";

    if (myFileName.indexOf(".indd") != -1) {

        var myRegularExpression = /.indd/gi;

        myFileNamePDF_Web = myFileName.replace(myRegularExpression, ".pdf");

    }

    with(app.pdfExportPreferences) {

        PDFJPEGQualityOptions.HIGH;

        PdfMagnificationOptions.FIT_PAGE;

        PageLayoutOptions.SINGLE_PAGE;

        colorBitmapCompression = BitmapCompression.zip;

        colorBitmapQuality = CompressionQuality.eightBit;

        colorBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE;

        colorBitmapSamplingDPI = 300;

    }

    myDocument.exportFile(ExportFormat.INTERACTIVE_PDF, new File(myFileNamePDF_Web));

} else {

    alert("Save your file before continuing");

}

This topic has been closed for replies.

3 replies

Ugo G.Author
Participating Frequently
May 10, 2016

now believe it has to do with the ExportFormat option.

see i can output a pdf with no error using:

myDocument.exportFile(ExportFormat.PDF_type, new File(myFileNamePDF_Web));

but when i use :

myDocument.exportFile(ExportFormat.INTERACTIVE_PDF, new File(myFileNamePDF_Web));

i have a problem.

So somewhere there's a ExportFormat.PDF_type VS ExportFormat.INTERACTIVE_PDF situation that i cant figure out =/

Community Expert
May 10, 2016

I did not test your code Ugo G.

But you will run into trouble sooner or later.

Why? Run the following snippet:

// Your RegExp:

var myRegularExpression = /.indd/gi;

/*

    Test your regular expression against this one here:

    var myRegularExpression = /\.indd$/i;

*/

var myInDesignName = "Finddress-Fashion-Catalogue.indd";

var myPDFName = myInDesignName.replace(myRegularExpression, ".pdf");

alert

(

    "Before/After"+"\r"+

    myInDesignName+"\r"+

    myPDFName

);

/*

    Your RegExp will create a file name with a dot at the start in this example.

    On OSX this file will be invisible in the Finder.

*/

Uwe

Ugo G.Author
Participating Frequently
May 10, 2016

Uwe, thank for pointing that out! I'm not all that familiar with regex and since it worked so far i was confident it was ok! Phew!

tpk1982
Legend
May 10, 2016

Hi,

I tried the above coding and it is working fine.. can you please share screenshot of error

Ugo G.Author
Participating Frequently
May 10, 2016

tpk1982 : this is the error box that pops on SOME documents. I was not able to figure out what causes the error in those documents.

First i thought this had to do with the pdf preferences, but further testing showed it wasn't the case.

It seems to break at the exportFil on line 19.

Community Expert
May 10, 2016

Ugo G. wrote:

tpk1982 : this is the error box that pops on SOME documents. I was not able to figure out what causes the error in those documents.

First i thought this had to do with the pdf preferences, but further testing showed it wasn't the case.

It seems to break at the exportFil on line 19.

Well, it could be that you are knocking at some limits of the overall pixel size of exported images regarding width or height (or maybe the product of height and width) that is perhaps with InDesign.

Reminds me of PhotoShop:

Photoshop image size and resolution

Photoshop supports a maximum pixel dimension of 300,000 by 300,000 pixels per image. This restriction places limits on the print size and resolution available to an image.

I found hints, that in older versions of PhotoShop this limit was 30,000 by 30,000 pixels.

Maybe there are other limits at play here.
Will the export go well, if you reduce the resolution to 72 ppi or less for colorBitmapSamplingDPI ?

Uwe