PDF In-Depth

Moonshine2: The art of Scripting to make your own Distillery

Inside Moonshine2

Advertisement
 

In order to give you a better idea of what's actually "under the hood" of Moonshine2, the script is included below, along with comments for each line as appropriate.


// This opens each of the found PDFs ([i] is the iteration, or individual

// file) using a set of pdfOpenOptions
// To modify the PDF Open Options
open(pdfsInFolder[i],pdfOpenOptions);
// create a new PDFOpenOptions setting:
var pdfOpenOptions = new PDFOpenOptions();
// constrain the proportions such that a scaled file, based on the
// width requested is generated
pdfOpenOptions.constrainProportions = true;
// This sets the width of the resulting image
pdfOpenOptions.width = request.WidthOfOutputJPEG;
// open as an RGB image; other alternatives include Grayscale and CMYK
pdfOpenOptions.mode = OpenDocumentMode.RGB;
// this is the requested DPI
pdfOpenOptions.resolution = request.DPIOfOutputJPEG;
// These settings are passed into the open command as used above.
// To modify the JPEG save Options; the color space and DPI are in the
// document as determined by the PDF open options above.
// create a new JPEGSaveOptions setting as used in the save command
jpgSaveOptions = new JPEGSaveOptions();
// quality of JPEG output in a scale of 1 to 12 (lowest to highest quality)
jpgSaveOptions.quality = request.QualityOfOutputJPEG;
// Once open, the next step is to save the JPEG:
app.activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
// This simply saves the open document as a JPEG
// To wrap script into Windows:
aPhotoshop.DoJavaScriptFile pathToPhotoshopScripts, params

Why not write the whole script in AppleScript or VBScript? By using the JavaScript engine, the bulk of the scripting work is cross-platform: creating the bulk of the script in one single language. As there is limited file system support in the JavaScript engine, to permit full access to the operating system a native scripting language and environment would be required. This script has little to no need to deeply get data from other applications. If it did, using a platform-specific language would need to be used.

Moonshine2 has little operating system integration, however to show the integration there is a sample VBScript (MoonshineStart.vbs) that passes variables to the JavaScript and asks Photoshop to execute the script.

Left to the Reader

JPEG is just one of many output formats supported by Photoshop CS. This script could save TIFF, GIF, Targa or many of the formats that Photoshop supports. Other additions could be the addition of watermarks prior to saving as an image for protection.

Adobe engineers scripting as a core part of the applications -- realizing that many customers will need alter the software in ways specific to their environments. Making your own Distillery is still legal -- at least with scripting.

Nick Hodge, from Adobe Systems in Australia, is attempting to become an Adobe renaissance man. Sales by day, scripting by night.

This article appeared in its original form at nickhodge.com. It has been updated by the author and reproduced with permission.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.