2009年9月21日月曜日

イラレで差し込み印刷気分



タブ区切りなaddr.txtを読んで、イラレのなかのaddrとか書いてある文字を置換してpdfに吐く方法。


↓このへんを参考にして、ぺちぺち書いてみた。


http://www.openspc2.org/book/IllustratorCS/normal/007/index.html






TABCODE = String.fromCharCode(9); // タブコード
CRCODE = String.fromCharCode(10); // 改行コード


fileRef = new File ("/Users/akira/work/addr/addr.txt");
flag = fileRef.open ("r");
tmp = fileRef.read();
text = tmp.split(CRCODE);
for (i=0; i<text.length; i++)
{

str = text[i].split(TABCODE);
data_id=str[0];
data_name=str[1];
data_zipcode=str[2];
data_addr=str[3];
template=open(new File ("/Users/akira/work/addr/template.ai"));


sel = template.pageItems;
regName = new RegExp("name", "g");
regZipcode = new RegExp("zipcode", "g");
regAddr = new RegExp("addr", "g");
for (j=0; j< sel.length; j++)
{
selObj = sel[j];

if(selObj.typename == "TextFrame"){

selObj.contents = selObj.contents.replace(regName,data_name);
selObj.contents = selObj.contents.replace(regAddr,data_addr);
selObj.contents = selObj.contents.replace(regZipcode,data_zipcode);
}
}


pdfOpt = new PDFSaveOptions();
pdfOpt.compatibility = PDFCompatibility.ACROBAT6;
saveFile = new File("/Users/akira/work/addr/out"+data_id+".pdf");
activeDocument.saveAs(saveFile, pdfOpt);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);


}





0 件のコメント:

コメントを投稿