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

How do I insert my csv file column value into a text frame placeholder with javascript?

New Here ,
Apr 30, 2015 Apr 30, 2015

Hi guys i'm a beginner when it comes to scripting in general and I got an assignment .

I'm working on a web api which needs to produce an empty indd Document and fill it with content with the help of a csv file(datamerge) and convert it to a pdf afterwards. Im currently using the InDesign server and a soap client to insert my task with scripts in it to accomplish this. In the script below I am trying put the header column into a placeholder text frame in InDesign. the problem is that when i run this I get the error  " Missing placeholders". so the script can't put the csv content in a placeholder. I am stuck at this error, please help me if you can.


code below:


var source = File("/c/xampp/htdocs/project/data/indd/hello1.indd");// indesign source
var destination = File("");
var sourceData = File("/c/xampp/htdocs/project/data/csv/data1.csv"); csv file

  //Create a new document.
  var myDocument = app.documents.add();
  //Get a reference to the first page.

  var myPage = myDocument.pages.item(0);
  //Create a text frame.
  var myTextFrame = myPage.textFrames.add();
  var myTextFrame = myPage.textFrames.add({geometricBounds:[60,30,35,85]});
  var myTextFrame1 = myPage.textFrames.add();
  var myTextFrame1 = myPage.textFrames.add({geometricBounds:[110,30,310,170]});

  myDocument.dataMergeProperties.selectDataSource(sourceData);


myTextFrame.contents = TextFrameContents.placeholderText;
myTextFrame1.contents = TextFrameContents.placeholderText;

var myDataMergeProperties= myDocument.dataMergeProperties;

myDocument.dataMergeProperties.mergeRecords();

//Save the document.
myDocument.save(new File("/c/xampp/htdocs/project/data/indd/hello2.indd"));
//Close the document.
app.documents.item(0).close();


app.activeDocument.save(File("/c/xampp/htdocs/project/data/indd/he.indd"));
app.documents.item(0).exportFile(ExportFormat.pdfType, destination);
doc.close();




the csv file looks like this when opened in notepad :


Klant,Content

Johan,LAKDASDMASDASDJASDASDAD

Susan,waLALALALLALALLALALALALALANANANnana

Jack,eensLALALALLALALLALALALALALANANANnana

Daniel,eenLALALALLALALLALALALALALANANANnana

any help would be appreciated!

TOPICS
Scripting
466
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
Mentor ,
May 04, 2015 May 04, 2015
LATEST

Hi,

Explain more what is your goal, pls - how your indd doc supposes to look like.

Use "merge" for creatiing many docs (pages) with different data collected in your csv file rather.

Perhaps just "place" method is a solution for you? And convert a content to table afterwards?

I mean:

myTextFrame.place(sourceData);


Jarek

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