How to automate InDesign data merge with C#
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,
