Created
December 19, 2012 18:53
-
-
Save brysonian/4339349 to your computer and use it in GitHub Desktop.
Simple InDesign script to load content from a CSV file and create a page for each record.
The contents of each row are joined and inserted into the master page item with the "content" script label.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Simple InDesign script to load content from a CSV file and create a page for each record. | |
The contents of each row are joined and inserted into the master page item with the "content" script label. | |
Requres agnes.js for CSV parsing <http://www.secretgeek.net/agnes11.asp> | |
A sample InDesign file can be found at https://dl.dropbox.com/u/57593/cards.indd | |
*/ | |
(function(){ | |
var doc = app.documents[0] | |
, docroot = "/Some/file/path" | |
, data = new File(docroot + "/didactics.csv") | |
, master = "A-Card" | |
, csv | |
, page | |
, item | |
, contentTextFrame; | |
data.open('r'); | |
$.evalFile(new File(docroot + "/agnes.js")); | |
csv = agnes.csvToJson(data.read()); | |
for (var p in csv) { | |
page = doc.pages.add(); | |
page.appliedMaster = doc.masterSpreads.item(master); | |
item = getContentTextFrame(page); | |
contentTextFrame = item.override(page); | |
contentTextFrame.geometricBounds = item.geometricBounds; | |
contentTextFrame.contents = formatOutput(csv[p]); | |
} | |
function formatOutput(row) { | |
return [ | |
row['Title of the work'], | |
row['Your Name'], | |
row['Year'], | |
row['Dimensions'], | |
row['Materials'] | |
].join('\n') | |
} | |
function getContentTextFrame(page) { | |
for (var i=0; i<page.masterPageItems.length; i++) | |
if (page.masterPageItems[i].label == 'content') return page.masterPageItems[i]; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment