Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Data Merge?

Guest
Jul 30, 2012 Jul 30, 2012

I am laying out a conference syllabus and have run into a snag. I was 

provided about 550 pages of PDFs, which I flowed into an InDesign file 

using a script. They look fine. I placed a footer, but now am in a 

pickle for getting a customized header for each of the syllabus 

documents (about 180 lectures account for those 550 pages). I don't want 

to take the time to go in page by page and type or paste in the text 

manually. I have the information that needs to run in the header in 

excel, but cannot think of a way to use data merge or text variables (or 

anything else!) to get the excel data onto the right pages.

Any ideas?

TOPICS
Scripting
1.6K
Translate
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

correct answers 1 Correct answer

Guru , Aug 01, 2012 Aug 01, 2012

Hi Matt

I hope you did not have a heart attack from my $15, I wouldn't want Interpol onto me.

Anyway here's 2 scripts the first one places  threaded text frame on every page you can then place the excel data in the way described on the link above.

The second script puts not threaded text frames on every page and places the contents of an array into  the frames for each new section the next item in the array fill the frames until the next section and so on.

To fill the array with the contents of the

...
Translate
Guru ,
Jul 30, 2012 Jul 30, 2012

DEPENDING on what exactly you want to do this link might well help.

It is not through scripting but should get the job done very quickly.

Will thread the list through the document page after page.

i.e. page 1 will get heading 1 page 2 heading 2 etc. Just enter Return before each Item if it needs pushing off.

If heading 2 is on page 5 press enter 4 times.

Shouldn't take more than 30 minutes for 550 pages

http://forums.adobe.com/message/3792615#3792615

Trevor

Translate
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
Guest
Jul 31, 2012 Jul 31, 2012

Thanks, Trevor. Works as advertised. Very cool. I was thrown a curveball, however (like that ever happens... ) The 550 pages are made up of about 183 different sections (different lectures with a variable number of pages), so I might be out of luck.

Any other ideas come to mind? (from Trevor, or others) I had heard offline that this might be achievable with a script...

Thanks for any help.

Matt

Translate
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
Guru ,
Jul 31, 2012 Jul 31, 2012

I understand you mean that each section has a different master, if so that would spoil your fun considerably!

I think it would be helpful to see a screen shot of a small part of the excel file you wish to import (change any parts you don't want people to see!!)

I presume that you have no reference to the page numbers in that document if you were to add them in that would make the job easy but even if not if for each section you move on one item in the excel list then it doesn't sound to tough.

Do you have basic scripting skills and are looking for guidance or are you looking for the script written for you? (Sounds like about $15 to me)

Don't expect any quick answer from me, I'm going out now,

Bye

Translate
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
Guru ,
Aug 01, 2012 Aug 01, 2012

Hi Matt

I hope you did not have a heart attack from my $15, I wouldn't want Interpol onto me.

Anyway here's 2 scripts the first one places  threaded text frame on every page you can then place the excel data in the way described on the link above.

The second script puts not threaded text frames on every page and places the contents of an array into  the frames for each new section the next item in the array fill the frames until the next section and so on.

To fill the array with the contents of the excel file, place the file in a new indesign document then useing ctrl f replacing tabs / returns for ", " the is a quote mark, coma, quote mark copy this new contents to the script instead of fred","Harry","Trevor at the begining of the script.

Both scripts give the text frame an object style "Trevor's Object Style" with a paragraph syle "Trevor's Paragraph Style"

Script 1

// Script 1 for semi-automatic data import

// http://forums.adobe.com/thread/1042222?tstart=0

myDoc=app.documents[0];

if (myDoc.pages.length>1) app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Make Text Frames for Semi Manual Excel Data Entry");

function main()

{

pageBounds=[]; 

pageBounds[0]=myDoc.pages.item(0).bounds;

pageBounds[1]=myDoc.pages.item(1).bounds;

topMargin=myDoc.pages.item(0).marginPreferences.top;

leftMargin=myDoc.pages.item(0).marginPreferences.left;

rightMargin=myDoc.pages.item(0).marginPreferences.right;

leftMargin2=myDoc.pages.item(1).marginPreferences.left;

rightMargin2=myDoc.pages.item(1).marginPreferences.right;

frameBounds=[];

frameBounds[0]=[0,0,0,0]

frameBounds[1]=[0,0,0,0];

frameBounds[0][0]=topMargin-8+pageBounds[0][0]; // top y of text frame of odd pages change as needed

frameBounds[0][2]=topMargin+pageBounds[0][0]; // bottom y of text frame of odd pages change as needed

frameBounds[1][0]=topMargin-8+pageBounds[1][0]; // top y of text frame of even pages change as needed

frameBounds[1][2]=topMargin+pageBounds[1][0]; // bottom y of text frame of even pages change as needed

frameBounds[0][1]=leftMargin+pageBounds[0][1]; // left x of text frame of odd pages change as needed

frameBounds[0][3]=pageBounds[0][3]-rightMargin; // right x of text frame of odd pages change as needed

frameBounds[1][1]=pageBounds[1][1]+leftMargin2; // left x of text frame of even pages change as needed

frameBounds[1][3]=pageBounds[1][3]-rightMargin2; // right x of text frame of even pages change as needed

tps=myDoc.paragraphStyles.add({name: "Trevor's Paragraph Style",justification: Justification.AWAY_FROM_BINDING_SIDE});

tos=myDoc.objectStyles.add({name: "Trevor's Object Style", appliedParagraphStyle: tps, enableParagraphStyle: 1});

oldTextFrame=myDoc.pages.item(0).textFrames.add({geometricBounds: frameBounds[0], label: "Trevor's Text Frame", appliedObjectStyle: tos});

for (c=1; c<myDoc.pages.length; c++)

  {

      newTextFrame=myDoc.pages.item(c).textFrames.add({label: "Trevor's Text Frame", geometricBounds: frameBounds[(c%2)], previousTextFrame: oldTextFrame, appliedObjectStyle: tos});

      oldTextFrame=newTextFrame;

   } 

}

Script 2

// Script 2 for automatic data import

// http://forums.adobe.com/thread/1042222?tstart=0

myDoc=app.documents[0];

myHeaders=["fred","Harry","Trevor"];

if (myDoc.pages.length>1) app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Make Text Frames for Semi Manual Excel Data Entry");

function main()

{

pageBounds=[]; 

pageBounds[0]=myDoc.pages.item(0).bounds;

pageBounds[1]=myDoc.pages.item(1).bounds;

topMargin=myDoc.pages.item(0).marginPreferences.top;

leftMargin=myDoc.pages.item(0).marginPreferences.left;

rightMargin=myDoc.pages.item(0).marginPreferences.right;

leftMargin2=myDoc.pages.item(1).marginPreferences.left;

rightMargin2=myDoc.pages.item(1).marginPreferences.right;

$.writeln(pageBounds[0]+"\r\r"+pageBounds[1]+"\r\r"+topMargin+"\r"+leftMargin+"\r"+rightMargin+"\r"+leftMargin2+"\r"+rightMargin2);

frameBounds=[];

frameBounds[0]=[0,0,0,0]

frameBounds[1]=[0,0,0,0];

frameBounds[0][0]=topMargin-8+pageBounds[0][0]; // top y of text frame of odd pages change as needed

frameBounds[0][2]=topMargin+pageBounds[0][0]; // bottom y of text frame of odd pages change as needed

frameBounds[1][0]=topMargin-8+pageBounds[1][0]; // top y of text frame of even pages change as needed

frameBounds[1][2]=topMargin+pageBounds[1][0]; // bottom y of text frame of even pages change as needed

frameBounds[0][1]=leftMargin+pageBounds[0][1]; // left x of text frame of odd pages change as needed

frameBounds[0][3]=pageBounds[0][3]-rightMargin; // right x of text frame of odd pages change as needed

frameBounds[1][1]=pageBounds[1][1]+leftMargin2; // left x of text frame of even pages change as needed

frameBounds[1][3]=pageBounds[1][3]-rightMargin2; // right x of text frame of even pages change as needed

tps=myDoc.paragraphStyles.add({name: "Trevor's Paragraph Style",justification: Justification.AWAY_FROM_BINDING_SIDE});

tos=myDoc.objectStyles.add({name: "Trevor's Object Style", appliedParagraphStyle: tps, enableParagraphStyle: 1});

oldTextFrame=myDoc.pages.item(0).textFrames.add({geometricBounds: frameBounds[0], label: "Trevor's Text Frame", appliedObjectStyle: tos});

oldMaster=myDoc.pages.item(0).appliedMaster;

oldTextFrame.parentStory.contents=myHeaders[0];

arrayCount=0;

for (c=1; c<myDoc.pages.length; c++)

  {

      newTextFrame=myDoc.pages.item(c).textFrames.add({label: "Trevor's Text Frame", geometricBounds: frameBounds[(c%2)], appliedObjectStyle: tos});

      newMaster=myDoc.pages.item(c).appliedMaster;

      (oldMaster!=newMaster && arrayCount!=myHeaders.length-1) ? arrayCount++:0;

      newTextFrame.parentStory.contents=myHeaders[arrayCount];

   } 

}

I wouldn't say no to the $15

Trevor

Translate
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
Guest
Aug 01, 2012 Aug 01, 2012

Trevor,

I was up against the deadline and ended up needing to get the headers placed, so I went ahead and did it manually using a table set in the header on the master page that matched the table of information as imported from excel. It was a tedious, but simple cut and paste that will allow me to adjust the header styles after the fact.

Thanks for your work on these scripts. Though I won't be able to use them, now I know where to go for expert scripts to solve unique problems.

Thanks again!

Matt

Translate
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
Guru ,
Aug 01, 2012 Aug 01, 2012

No problem Matt, at least you made your deadline.

Please mark the scripts as correct instead of helpful (I'm pretty sure there correct)

Thanks

Trevor

Translate
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
Guru ,
Aug 01, 2012 Aug 01, 2012
LATEST

I made another script that imports the headers straight from an excel file

The file should be saved from excel as a prn file.

Saving in this format seems to be the only way to deal with cells that contain quotes, apostrophes, commas etc.

The script presumes that you have a single column list of headers.

(Matt I know this is not needed by you any more)

Trevor

// Script 3 for automatic data import from prn excel file

// http://forums.adobe.com/thread/1042222?tstart=0

myDoc=app.documents[0];

if (myDoc.pages.length>1) app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Make Text Frames for Semi Manual Excel Data Entry");

function main()

{

var myprn = "c:/numberList.prn"; //path to the prn file

myHeaders=parsePRN(myprn);

pageBounds=[]; 

pageBounds[0]=myDoc.pages.item(0).bounds;

pageBounds[1]=myDoc.pages.item(1).bounds;

topMargin=myDoc.pages.item(0).marginPreferences.top;

leftMargin=myDoc.pages.item(0).marginPreferences.left;

rightMargin=myDoc.pages.item(0).marginPreferences.right;

leftMargin2=myDoc.pages.item(1).marginPreferences.left;

rightMargin2=myDoc.pages.item(1).marginPreferences.right;

frameBounds=[];

frameBounds[0]=[0,0,0,0]

frameBounds[1]=[0,0,0,0];

frameBounds[0][0]=topMargin-8+pageBounds[0][0]; // top y of text frame of odd pages change as needed

frameBounds[0][2]=topMargin+pageBounds[0][0]; // bottom y of text frame of odd pages change as needed

frameBounds[1][0]=topMargin-8+pageBounds[1][0]; // top y of text frame of even pages change as needed

frameBounds[1][2]=topMargin+pageBounds[1][0]; // bottom y of text frame of even pages change as needed

frameBounds[0][1]=leftMargin+pageBounds[0][1]; // left x of text frame of odd pages change as needed

frameBounds[0][3]=pageBounds[0][3]-rightMargin; // right x of text frame of odd pages change as needed

frameBounds[1][1]=pageBounds[1][1]+leftMargin2; // left x of text frame of even pages change as needed

frameBounds[1][3]=pageBounds[1][3]-rightMargin2; // right x of text frame of even pages change as needed

tps=myDoc.paragraphStyles.add({name: "Trevor's Paragraph Style",justification: Justification.AWAY_FROM_BINDING_SIDE});

tos=myDoc.objectStyles.add({name: "Trevor's Object Style", appliedParagraphStyle: tps, enableParagraphStyle: 1});

oldTextFrame=myDoc.pages.item(0).textFrames.add({geometricBounds: frameBounds[0], label: "Trevor's Text Frame", appliedObjectStyle: tos});

oldMaster=myDoc.pages.item(0).appliedMaster;

oldTextFrame.parentStory.contents=myHeaders[0];

arrayCount=0;

for (c=1; c<myDoc.pages.length; c++)

  {

      newTextFrame=myDoc.pages.item(c).textFrames.add({label: "Trevor's Text Frame", geometricBounds: frameBounds[(c%2)], appliedObjectStyle: tos});

      newMaster=myDoc.pages.item(c).appliedMaster;

      (oldMaster!=newMaster && arrayCount!=myHeaders.length-1) ? arrayCount++:0;

      newTextFrame.parentStory.contents=myHeaders[arrayCount];

   } 

}

function parsePRN(filePath){

    // this function is based on a function written by Haakenlid  http://forums.adobe.com/message/3666148#3666148

     var prnfil;

     var result;

     prnfil=new File(filePath);

     prnfil.open();

     fileContent = prnfil.read();

     prnfil.close();

    // eval("result=['"+fileContent.replace(/,/g, "','")+"'];");

    myArrayString=fileContent.replace(/'/g, "QtQeQn4").replace(/\t/g, "','").replace (/\n/g, "' , '");

    myArrayString=myArrayString.slice(0,-3);

    $.writeln(myArrayString);

        eval ("result=['"+myArrayString+"];");

        for (var c=0; c<result.length-1; c++) result=result.replace(/QtQeQn4/g, "'");

     return result;

};

Translate
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