javascript - Adobe InDesign Javascript 错误!错误号:55 错误字符串:对象不支持属性或方法“documentPreferences”
问题描述
当我尝试在 InDesign 中运行以下代码时出现错误。我实际上是直接从 Adobe 教程中获取此代码的,不知道他们为什么会弄错自己的代码。任何您能提供帮助的方式将不胜感激!谢谢。
try{myFont = app.fonts.item("Arial");
}
catch (myError){};
var myDocument = app.documents.item(0);
with(myDocument){
var myPage = pages.item(0);
var myBounds = myGetBounds(myPage,myDocument);
with(myDocument.pages.item(0)){
//Get a reference to the text frame.
var myTextFrame = textFrames.item(0);
//Change the size of the text frame.
myTextFrame.geometricBounds = myBounds;
var myParagraph = myTextFrame.paragraphs.item(0);
myParagraph.appliedFont = myFont;
myParagraph.justification = Justification.centerAlign;
myParagraph.pointSize = 48;
}
}
//myGetBounds is a function that returns the bounds
//of the "live area" of a page.
function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight;
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
}else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
}
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
解决方案
看起来在myGetBounds()
函数中您以错误的顺序传递参数。
在函数定义中,您可以看到应该首先传递文档,然后再传递页面,但在从var myBounds
您开始的行中则相反。
所以这条线应该是:
var myBounds = myGetBounds(myDocument, myPage);
推荐阅读
- bash - 如何以相同的输出多次运行 bash 脚本?
- android - 构建一个自定义appbar android,里面有圆形图像和两行标题
- firebase - 如何在flutter中使用linkwithcredential函数。当用户已经向不同的身份验证提供者注册时出现错误。无法链接
- python - 删除 HTML 文件中的强标签
- javascript - 如何在向表中添加列时动态更改列标题
- pci - 了解清除 PCI 错误位
- apache-flink - 在 Flink SQL 流中的“Group Aggregation”子查询之后使用“Over Aggregation”
- javascript - 节点mysql2不正确的参数语句
- firebase - 将 Cloud Functions 与 Firebase 托管配对有哪些优势?
- html - 悬停时css更改按钮颜色