ฉันยังใหม่กับการเขียนสคริปต์ indesign ฉันต้องการคำแนะนำในการเขียนสคริปต์ jsx ฉันมีเทมเพลต indesign (ไฟล์ indt) และฉันต้องสร้างไฟล์ indd จากมัน (เพียงสำเนา) จากนั้นฉันต้องแทนที่ชื่อ/นามสกุลและวันที่ ฯลฯ ด้วยเนื้อหาที่ฉันอ่านจาก xml
จนถึงตอนนี้ฉันชอบสิ่งนี้:
function buildIndesignDocument(templatePath, templateFileName, targetPath, xmlFile, orderNumber, jobNumber) {
DEBUGG("buildIndesignDocument execution start");
//check wheher target path is writable. If not exit from further processing
var canSaveToServerFlag = checkServerWritable(targetPath.toString());
if(!canSaveToServerFlag) {
DEBUGG("Exiting from the process");
return;
}else{
var originalTemplateFilePath = templatePath+templateFileName;
DEBUGG("Original Template Path is " + originalTemplateFilePath);
var originalTemplate = new File(originalTemplateFilePath);
var filePrefix =jobNumber.toString()+"_"+orderNumber.toString()+ "_";
if (originalTemplate.exists) {
//create a copy of the template in target folder and name it as indd
targetFileName= filePrefix+templateFileName.replace(".indt", ".indd");
DEBUGG("target FileName is " + targetFileName);
var targetFile =targetPath.toString() + targetFileName ;
DEBUGG("target FilePath and name is " + targetFile);
var targetFileCreated=originalTemplate.copy(File(targetFile));
// if(targetFileCreated.exists){
// TODO####hardcoded true need to change
if(true) {
DEBUGG("targetFile Created Successfully" + targetFileCreated);
var xmlFormFile =getGenericXmlFile(xmlFile);
DEBUGG("xmlFormFile is -----------" +xmlFormFile);
var firstName = xmlFormFile.xpath("/formData/firstName");
var lastName = xmlFormFile.xpath("/formData/lastName");
DEBUGG("firstName----------"+firstName + " and last name is ----------" +lastName );
//Open the indd file and replace the content with form data preserving format and style
var inddFile = new File(targetFile);
try {
DEBUGG("inside try");
//open file for write -mode w is write
inddFile.open ("w", null, null);
var myDoc=inddFile.read ();
DEBUGG("after opening"+myDoc.toString());
inddFile.close;
} catch(e) {
DEBUGG("Exception in opening " + e.description);
inddFile.close;
}
} else {
DEBUGG("targetFile did not create successfully");
}
} else {
DEBUGG("Template not Found");
logError("Missing template file with name ==" +originalTemplateFilePath);
}
DEBUGG("buildIndesignDocument execution end");
}
}
}
ฉันไม่สามารถเปิดไฟล์ได้อย่างถูกต้องและแทนที่เนื้อหาได้ ใครสามารถให้ความกระจ่างเกี่ยวกับเรื่องนี้ได้บ้าง
var myDocument = app.open(File(targetFile))
? - person cybernetic.nomad   schedule 15.08.2018