Created

Jun 21, 2013

InDesign Server Scripts in AEM DAM

Posted by Ugo Cei

AEM DAM supports InDesign documents in a limited way out of the box, but many more options are available through the use of the Adobe InDesign Server product. In this blog post, we'll have a look at what extra features are enabled when an InDesign Server is present and also at what else can be obtained by customizing the InDesign Server Scripts that are included in AEM DAM.

What is Adobe InDesign Server?

Adobe InDesign Server is an engine that leverages the design, layout, and typographical capabilities of InDesign CS6 to let you programmatically create automated documents. InDesign operations can be scripted using an implementation of JavaScript that Adobe calls ExtendScript.

How is InDesign used by AEM DAM?

The DAM Update Asset workflow that is included in AEM has a step called Media Extraction. The configuration for the step includes a list of scripts that are executed sequentially when an INDD document is uploaded to DAM or updated. By default, those are:

/etc/dam/indesign/scripts/ThumbnailExport.jsx
Generates a JPEG thumbnail of the document's front page.


/etc/dam/indesign/scripts/XHTMLExport.jsx
Generates an HTML representation of the InDesign document


/etc/dam/indesign/scripts/IDMLExport.jsx
Generates an IDML file (XML-based markup describing the structure and contents of the document).

InDesign exposes its services using SOAP on a TCP port that must be specified on the command line that is used to start the server. Here is the command used to tell InDesign Server to listen on TCP port 8080:

<path-to-installation-directory>/InDesignServer -port 8080

On AEM's side, the connection is configured in the Cloud Services > Cloud Proxy Configuration > IDS worker section of the Tools console (http://server:port/etc/cloudservices/proxy/ids.html). By default, AEM is configure to connect to InDesign at http://localhost:8080, so you don't normally have to change that, unless port 8080 is used by some other application or InDesign Server is running on a remote host.

InDesign Scripting

Giving a tutorial on InDesign scripting is beyond the scope of this post, but you can peruse the Adobe InDesign CS6 Server Scripting Guide to learn how to do it (see the Resources section). It is instructive to look at the existing scripts, if all you need is to extend the base functionality, as we will do in the next section. You can find those in CRX, under /etc/dam/indesign/scripts.

Sample Scripts

We will show two sample scripts to illustrate some of the capabilities of InDesign. These scripts are based on the original ThumbnailExport.jsx one and extend it to generate thumbnails for all the pages in a document, in either JPEG or PDF format.

You can find these two scripts in this package. To activate them, add them to the list of scripts invoked by the Media Extraction step in the DAM Update Asset workflow.

Let's have a look at the PdfExportPages.jsx script. If you compare it with ThumbnailExport.jsx, you will notice the similarities. The main difference is the addition of code to loop over all pages in the current document:

for (var i = 0 ; i < document.pages.length ; ++i) {
    exportPage(document, i, exportFolder.fullName, fileName, resourcePath, host, credentials);
}

Here is the full source code of the script:

//==============================================================================
// Export any Indesign document as PDF
//==============================================================================

//==== get soap arguments ====
if (app.scriptArgs.isDefined("credentials")) {
    var credentials = app.scriptArgs.getValue("credentials");
} else {
    throw "CQ host credentials argument is missing";
}
if (app.scriptArgs.isDefined("cqHost")) {
    var host = app.scriptArgs.getValue("cqHost");
} else {
    throw "cqHost argument is missing";
}
if (app.scriptArgs.isDefined("resource")) {
    var resourcePath = app.scriptArgs.getValue("resource");
} else {
    throw "resource argument is missing";
}


try {
    //==== create a temporary folder under InDesign server tmp directory to fetch and export ====
    // added randomness to the folder name
    var exportFolder = new Folder("tmp-" + (new Date().getTime() - Math.floor((Math.random()*10000)+1) ));
    exportFolder.create();
    fileName = resourcePath.substring (resourcePath.lastIndexOf ('/'), resourcePath.lastIndexOf ('.'));
    var sourceFile = new File(exportFolder.fullName + fileName + '.indd');

    app.consoleout('Fetching resource from CQ: '+resourcePath);
    fetchResource (host,  credentials, resourcePath, sourceFile);

    var document = app.open(sourceFile);

    with (app.pdfExportPreferences) {
        viewDocumentAfterExport = false;
        exportingSpread = true;
    }
    for (var i = 0 ; i < document.pages.length ; ++i) {
        exportPage(document, i, exportFolder.fullName, fileName, resourcePath, host, credentials);
    }

    // close the document
    document.close(SaveOptions.no);

    //==== remove the original resource and send the export back to CQ ====
    sourceFile.remove();

    returnValue = "PDF exported and posted successfully";
} finally {
    //==== remove the temp folder ====
    cleanup(exportFolder);
}
app.consoleout('Finished PDF export...');

function exportPage(document, pageNo, folderName, fileName, resourcePath, host, credentials) {
    //app.pdfExportPresets.item("[Press Quality]");
    var pageName = document.pages.item(pageNo).name;
    app.pdfExportPreferences.pageRange = pageName;
    //The name of the exported files will be the base name + the
    //page name + ".pdf". If the page name contains a colon (as it will
    //if the document contains sections), then remove the colon.
    var regExp = /:/gi;
    pageName = pageName.replace(regExp, "_");
    var pageFileName = fileName + "_" + pageName + ".pdf";
    var filePath = folderName + pageFileName;
    app.consoleout('Writing page ' + i + ' to ' + filePath);
    var outputFile = new File(filePath);
    document.exportFile(ExportFormat.pdfType, outputFile);
    //==== send file to CQ ====
    var target = resourcePath.substring (0, resourcePath.lastIndexOf ('/')) + "/subassets";
    app.consoleout('Posting this file to CQ: ' + filePath);
    app.consoleout('Posting to location: ' + target);
    putResource (host, credentials, outputFile, pageFileName, 'application/pdf', target);
}

COMMENTS

  • By APK - 10:18 AM on May 31, 2014   Reply
    Many Thanks.
  • By dakwah dalam kubur - 1:02 AM on Jun 01, 2014   Reply
    I simply wanted to write down a quick word in order to say thanks to you for those wonderful tips and hints you are showing on this site.
    • By dakwah dalam kubur - 1:02 AM on Jun 01, 2014   Reply
      My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.
      • By dakwah dalam kubur - 1:04 AM on Jun 01, 2014   Reply
        My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.
        • By tidung.net - 4:57 AM on Jun 02, 2014   Reply
          Thanks.
          • By should you buy it - 3:41 PM on Jun 02, 2014   Reply
            You made a sick person fresh, I’m not kidding, I really wanted to read something and your blog fresh me up
            • By Cheap Traffic - 6:39 AM on Jun 03, 2014   Reply
              I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds
              • By hargaandroid.com - 8:49 AM on Jun 03, 2014   Reply
                Many Thanks.
                • By Planetwin365 - 11:30 AM on Jun 03, 2014   Reply
                  I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                  • By www YouTube - 1:35 PM on Jun 03, 2014   Reply
                    I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds
                    • By Halskæde Smykker - 6:29 AM on Jun 04, 2014   Reply
                      I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                      • By truth about cellulite - 8:27 PM on Jun 04, 2014   Reply
                        I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                        • By honey trick - 9:07 PM on Jun 04, 2014   Reply
                          My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.
                          • By how to do conversational hypnosi - 10:32 AM on Jun 05, 2014   Reply
                            I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site
                            • By North49Digital - 10:48 AM on Jun 05, 2014   Reply
                              My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends
                              • By Togel Hari Ini - 5:35 PM on Jun 05, 2014   Reply
                                Attachments help people a lot in effectively send and receive mail, with some more deeper and detail information to bring about. That's quite helpful to find out this new method to attach files in.
                                • By restore my vision today - 4:48 AM on Jun 06, 2014   Reply
                                  I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site
                                  • By apk - 11:14 AM on Jun 06, 2014   Reply
                                    Thanks.
                                    • Attachments help people a lot in effectively send and receive mail, with some more deeper and detail information to bring about. That's quite helpful to find out this new method to attach files in.
                                      • By Jasa SEO - 11:19 AM on Jun 08, 2014   Reply
                                        Many Thanks.
                                        • By Tattoos - 4:32 PM on Jun 08, 2014   Reply
                                          Many Thanks.
                                          • By step up height - 7:23 AM on Jun 09, 2014   Reply
                                            Before using step up height increaser I was short lean and a missing personality. But since I have started using step up height increaser, I started looking smart. The product has not just increased my height but has also enhanced my personality. Every short heighted person should try this.
                                            • By Commentmaster - 8:28 PM on Jun 09, 2014   Reply
                                              Actually get pleasure from this fantastic submit that you've got provided for people like us. Fantastic web page along with a wonderful topic also i really find amazed to learn to read this. Its fantastic.
                                              • By step up height increaser - 12:18 PM on Jun 11, 2014   Reply
                                                Really i am impressed from this post. The person who created this post is a genius and knows how to keep the readers connected.
                                                • By col3neg Italy - 4:54 AM on Jun 12, 2014   Reply
                                                  YouTube and the alike may also have some of the episodes you look for, but you know that the quality is usually poor and can really spoil the entire impression.
                                                  • By Obat Keputihan - 9:22 AM on Jun 22, 2014   Reply
                                                    Many Thanks.
                                                    • By Buy high pagerank Backlinks - 4:01 PM on Jun 29, 2014   Reply
                                                      strategy change for visually impaired readers? Would you simply eliminate references to illustrations or attempt to describe them.
                                                      • By motorcomcom - 7:42 AM on Jul 04, 2014   Reply
                                                        I simply get a crucial information right here and additionally this is often really Maine I trying. because of your current posting
                                                        • By resep kuliner kreatif - 7:43 AM on Jul 04, 2014   Reply
                                                          Your approach to this post is unique and appreciating. I am writing an article for our research paper and this post has helped me. Thanks
                                                          • By http://www.rebelmouse.com/ - 12:45 PM on Jul 06, 2014   Reply
                                                            This site is a leading resource for information about the James Ward Cruise Control Diet PDF book and complete weight loss system that teaches you a practical way to drop 10% of your body weight in 30 days or less and ultimately achieve permanent fat loss and better health.
                                                            • By best computer game - 6:03 AM on Jul 09, 2014   Reply
                                                              Glad to hear that adobe in design is available in market. I think there are many options available in the adobe in design version. Media extraction is highlighted feature in the adobe in design version. It will be very much useful to the photo workers.
                                                            • By clash of clans cheats - 10:44 AM on Jul 10, 2014   Reply
                                                              I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                              • By the venus factor book - 7:15 AM on Jul 12, 2014   Reply
                                                                OEmbed is a specification that provides an easy way to embed into a website digital media or HTML snippets which are hosted on a different website.
                                                                • By cek tagihan pln - 4:22 PM on Jul 12, 2014   Reply
                                                                  i really look tools from adobe. i like it.
                                                                  • By oily skin foundations - 9:20 AM on Jul 14, 2014   Reply
                                                                    Results vary from person to person and greatly depend on how your skin reacts to the ingredients contained in a particular foundation
                                                                    • By Yamaha R15 indonesia - 8:52 AM on Jul 15, 2014   Reply
                                                                      i really to say nice tools from adobe. i like it.
                                                                      • By Fast url opener - 5:44 PM on Jul 15, 2014   Reply
                                                                        Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.
                                                                        • By babyscream.com - 8:20 AM on Jul 18, 2014   Reply
                                                                          We were assisted by Jason McKinnon, manager of training and technical support, and Andy Richards, product trainer, when utilizing the tools and working on installations.
                                                                          • By duplichecker - 6:55 PM on Jul 18, 2014   Reply
                                                                            retty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.
                                                                            • By you can check here - 1:34 PM on Jul 23, 2014   Reply
                                                                              Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.
                                                                              • By reference link - 1:56 PM on Jul 24, 2014   Reply
                                                                                Its a great masterpiece written up here i wish to have a more brief reading of it now and in future.
                                                                                • By Erika Napoletano - 12:32 PM on Jul 25, 2014   Reply
                                                                                  Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.
                                                                                  • By click to read - 4:13 PM on Jul 28, 2014   Reply
                                                                                    I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                                                    • By lunatik coupon - 10:58 AM on Aug 04, 2014   Reply
                                                                                      Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”
                                                                                      • By outdoor furniture - 12:20 PM on Aug 05, 2014   Reply
                                                                                        I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                                                        • By Angmering - 10:19 AM on Aug 07, 2014   Reply
                                                                                          I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                                                          • By Termite Contol Fairfax - 9:44 AM on Aug 12, 2014   Reply
                                                                                            I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                                                            • By pusat crystal x jogja - 9:26 AM on Aug 13, 2014   Reply
                                                                                              I am not habituate to reply a comment on blogs but this blog caught my attention and I am compelled to write a comment here to express my gratitude to you. I would like to appreciate for this awesome work
                                                                                              • By distributor crystal x asli nasa - 9:27 AM on Aug 13, 2014   Reply
                                                                                                Good one. Very nice work. You've not exaggerated anything too much, you've kept it simple. It is good to see that. I hope your next articles will also be compromising of the same awesome quality as this article.
                                                                                                • By customer reviews - 12:03 PM on Aug 14, 2014   Reply
                                                                                                  YouTube and the alike may also have some of the episodes you look for, but you know that the quality is usually poor and can really spoil the entire impression.
                                                                                                  • By click here to learn more - 12:35 PM on Aug 14, 2014   Reply
                                                                                                    with some more deeper and detail information to bring about. That's quite helpful to find out this new method to attach files in.
                                                                                                    • By inbox blueprint  - 10:22 AM on Aug 15, 2014   Reply
                                                                                                      I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                                                                      • By http://www.presidentiallimousinevi.com/ - 11:12 AM on Aug 15, 2014   Reply
                                                                                                        I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.
                                                                                                        • By Youtube to mp3 - 10:34 AM on Aug 16, 2014   Reply
                                                                                                          I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds
                                                                                                          • By job search engine - 11:03 AM on Aug 18, 2014   Reply
                                                                                                            I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site
                                                                                                            • By www.jamiestaff.com - 8:59 AM on Aug 20, 2014   Reply
                                                                                                              I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two.

                                                                                                              ADD A COMMENT