Copy link to clipboard
Copied
"I am attempting to create a script to export a PDF from a data merge, but nothing is working.
Copy link to clipboard
Copied
Can you show your script?
Copy link to clipboard
Copied
// InDesign Script to Merge Data and Export as PDF
var savePath = "C:/Users/Samir/Desktop/Sam/Merged_Output.pdf";
// Check if a document is open
if (app.documents.length > 0) {
var doc = app.activeDocument;
// Check if Data Merge is set up
if (doc.dataMergeProperties && doc.dataMergeProperties.dataMergeFields.length > 0) {
var dataMerge = doc.dataMergeProperties;
try {
// Set Data Merge to merge ALL records into a new document
dataMerge.dataMergePreferences.recordSelection = RecordSelection.ALL_RECORDS;
// Merge all records into a new document
var mergedDoc = dataMerge.mergeRecords();
// Check if the merge was successful
if (mergedDoc) {
// Activate the merged document before exporting
app.activeDocument = mergedDoc;
// Try to get the PDF export preset
var pdfPresetName = "[High Quality Print]"; // Change if needed
var pdfPreset = null;
if (app.pdfExportPresets.itemByName(pdfPresetName).isValid) {
pdfPreset = app.pdfExportPresets.itemByName(pdfPresetName);
} else {
alert("Warning: PDF preset '" + pdfPresetName + "' not found. Using default settings.");
}
// Export the merged document as PDF
mergedDoc.exportFile(ExportFormat.PDF_TYPE, new File(savePath), false, pdfPreset);
// Close the merged document without saving
mergedDoc.close(SaveOptions.NO);
alert("PDF successfully exported to:\n" + savePath);
} else {
alert("Error: Merged document was not created.");
}
} catch (e) {
alert("Error during Data Merge or PDF Export:\n" + e.message);
}
} else {
alert("No Data Merge fields found. Please ensure a Data Merge file is linked.");
}
} else {
alert("No document open. Please open a document and try again.");
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Pretty sure this line:
var mergedDoc = dataMerge.mergeRecords()
Needs to be:
dataMerge.dataMerge.mergeRecords()
Chatgpt ain't too bright sometimes
Copy link to clipboard
Copied
I believe DataMergeExportFormat is not a valid object in InDesign scripting. I've tried multiple approaches, including AI, but none have worked. It seems that InDesign scripting doesn't support exporting Data Merge directly in the way I expected.
Copy link to clipboard
Copied
I believe DataMergeExportFormat is not a valid object in InDesign scripting. I've tried multiple approaches, including AI, but none have worked. It seems that InDesign scripting doesn't support exporting Data Merge directly in the way I expected.
By @samir_4316
What way do you expect?
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#DataMerge.html#d1e418772__d1e418948
"AI" lacks experience...
Copy link to clipboard
Copied
Did you try my solution?
Copy link to clipboard
Copied
"I am attempting to create a script to export a PDF from a data merge, but nothing is working.
By @samir_4316
Not sure how we can help you - without seeing your code...
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more