How to automate InDesign data merge with C#

New Here ,
Apr 14, 2018 Apr 14, 2018

Copy link to clipboard

Copied

I am trying to implement a solution where we can automate the data merge process offered by InDesign (see here: Merge data to create form letters, envelopes, or mailing labels in Adobe InDesign ).  I am currently using the COM interop classes from the SDK to achieve this, but I having trouble actually instantiating the classes required to actually execute the data merge.

I have an existing CSV file I will be using to conduct the import, and I have an existing InDesign file that can accept the mapping.

Here's what I have so far in terms of process:

  • Create an instance of the InDesign application (hiding the window)
  • Open the desired InDesign document
  • Provide the path to the CSV import file (not exactly sure where to do this)
  • Actually execute the data merge, and output the resulting PDF(s) (I think this is via either the DataMerge.exporFile or DataMerge.mergeRecords method, but not sure how to access those methods)
  • Retrieve the resulting PDF(s)

Basically, what is not clear in their SDK is the following:

  • What method do I use to supply the CSV import file for the data merge?
  • How do I actually instantiate the DataMerge class, once I have an existing Document object?
  • What's the difference between the DataMerge.exportFile or DataMerge.mergeRecords methods?

Also, we are planning to use similar logic on the InDesign server.  Will the same process from above be valid on InDesign server?

Thanks,

TOPICS
Scripting

Views

3.2K

Likes

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
Adobe Community Professional ,
Apr 14, 2018 Apr 14, 2018

Copy link to clipboard

Copied

You should ask in the SDK forum.

InDesign SDK

But are you developing a plugin? If you just need automation Javascript might be easier.

InDesign Scripting

Here's the JS API

InDesign ExtendScript API (10.0)

Likes

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
Adobe Community Professional ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

I agree with Rob, this is probably better answered in the InDesign Scripting forum, if one of the Mods could move this topic, that'd be grand.

In the meantime, I have written dozens of data merge scripts and make many of them freely available via my website www.colecandoo.com. Data Merge is easily scripted through the flavour of Javascript that InDesign uses, ESTK. Perhaps one of my scripts may already fulfil the task you are after.

FWIW, here is a very basic implementation of a javascript that will perform a data merge on an open document:

#target "InDesign"

       var myDoc = app.activeDocument;

        var myExport = File(app.activeDocument.filePath + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf");

with(myDoc.dataMergeProperties.dataMergePreferences) 

            { 

            recordSelection = RecordSelection.ALL_RECORDS; 

            } 

        app.dataMergeOptions.removeBlankLines = true;

                myDoc.dataMergeProperties.exportFile(myExport, "[High Quality Print]", );

Likes

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
Adobe Employee ,
May 29, 2018 May 29, 2018

Copy link to clipboard

Copied

LATEST

moved to InDesign Scripting

Likes

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