Copy link to clipboard
Copied
Hey!
I have a INDD file that has it's content flowed in from an XML, each field has a Tag and a Paragraph style applied to it.
I need to see if I can export a report of the Titles and what Page Number corresponds to each one, an Excel Or .CSV file would be ideal.
Anyone have any clues on who to do this from InDesign?
Thanks!
Copy link to clipboard
Copied
Why not generate a table of contents and then copy paste that text into a spreadsheet?
Copy link to clipboard
Copied
Hi @andyjamieson , A script could get every paragraph with a certain style applied and write the paragraph’s contents and its page number to a text or cvs file. Something like this gets all paragraphs with the style named Title and writes a Titles.cvs file to the desktop:
var sName = "Title"
var doc = app.activeDocument
var txt = "Title\tPage Number\r"
for(var i=0; i <doc.stories.length; i++){
var s = doc.stories.item(i);
for(var j=0; j < s.paragraphs.length; j++){
var p=s.paragraphs.item(j);
if (p.appliedParagraphStyle.name == sName ) {
txt += p.contents.slice(0,-1) + "\t" + p.parentTextFrames[0].parentPage.name + "\r"
}
}
}
writeText(Folder.desktop + "/Titles.csv", txt)
function writeText(p,s){
var file = new File(p);
file.encoding = 'UTF-8';
file.open('w');
file.write(s);
file.close();
}
Copy link to clipboard
Copied
Hey @rob day
That looks ideal, when I tried to create my own JSX script I get this error —
Here's an example of a listing with the file
Copy link to clipboard
Copied
Can you share the ID file? You should be able to attach it.
Copy link to clipboard
Copied
I've packaged one of the shorter sections, it's 20MB zipped so stuck it on Dropbox —
https://www.dropbox.com/s/we2visxw34142r9/Fringe_Programme_2022_EXHIBITIONS_v2%20Folder.zip?dl=0
Thank you for your help!
Copy link to clipboard
Copied
I should have clarified the first line in the sample script is the ParagraphStyle name to get—you don’t have a style named "Title", so if I use your "B_RuleShowName" style:
var sName = "B_RuleShowName"
var doc = app.activeDocument
var txt = "Title\tPage Number\r"
var pn;
for(var i=0; i <doc.stories.length; i++){
var s = doc.stories.item(i);
for(var j=0; j < s.paragraphs.length; j++){
var p=s.paragraphs.item(j);
if (p.appliedParagraphStyle.name == sName ) {
pn = p.parentTextFrames[0].parentPage.name
txt += p.lines[0].contents.slice(0,-1) + "\t" + p.parentTextFrames[0].parentPage.name + "\r"
}
}
}
writeText(Folder.desktop + "/Titles.csv", txt)
function writeText(p,s){
var file = new File(p);
file.encoding = 'UTF-8';
file.open('w');
file.write(s);
file.close();
}
I get this (note in this version I’m getting the first line of the title for the Title column):
Copy link to clipboard
Copied
Here’s the above code compiled:
https://shared-assets.adobe.com/link/a1fa5ed9-05f0-4e18-508e-5cd1cc1a4989
Copy link to clipboard
Copied
Excellent job Rob, just tried the script on a different file section it's throwning an error for Line 11
Will the script need slightly adjust for each file?
Copy link to clipboard
Copied
Will the script need slightly adjust for each file?
Yes if the header’s style name changes.
Also, if a text frame is on the pasteboard you would get that null error. This would set the page number to "PB" if the frame is not actually on a page. I updated the compiled link same address:
var sName = "B_RuleShowName"
var doc = app.activeDocument
var txt = "Title\tPage Number\r"
var pn;
for(var i=0; i <doc.stories.length; i++){
var s = doc.stories.item(i);
for(var j=0; j < s.paragraphs.length; j++){
var p=s.paragraphs.item(j);
if (p.appliedParagraphStyle.name == sName ) {
if (p.parentTextFrames[0].parentPage != null) {
pn = p.parentTextFrames[0].parentPage.name
} else {
pn = "PB"
}
try {
txt += p.lines[0].contents.slice(0,-1) + "\t" + pn + "\r"
}catch(e) {}
}
}
}
writeText(Folder.desktop + "/Titles.csv", txt)
function writeText(p,s){
var file = new File(p);
file.encoding = 'UTF-8';
file.open('w');
file.write(s);
file.close();
}