1

我正在为 adobe acrobat 开发 Javascript 插件。目标是为每个字段添加一个带有版本特定文本的字段。皱纹是页面大小不同,有些是纵向的,有些是横向的,我需要为每个页面放置适当的方向和位置。

我已经解决了大部分问题,但有一个问题。当此人以最终方向创建 PDF 页面(来自 CAD 程序)时,我的代码(如下)可以正常工作。但是,如果他们将页面创建为横向,然后使用 Adob​​e Acrobat 中的“旋转页面”功能使其显示为纵向,则图章会显示在正确的位置,但与我想要的方向有 90 度的偏差。(边界框也是 90 度偏离,导致文本非常小。)

如何检测页面是否像这样旋转,以便正确设置字段方向。或者,我可以使用不受旋转影响的单独坐标位置指定字段吗?

到目前为止,我的代码是:

function versionStamp()
{
    var oCurrentDate = new Date();
    var inch = 72;

    var newVersionLetter = app.response({
        cQuestion: "What is the new version letter?",
        cTitle: "Enter Version Letter",
        cDefault: " ",
        cLabel: "Rev",
    });

    if (newVersionLetter != null)
    {
        this.removeField("dateField");
        for (var p = 0; p < this.numPages; p++) {

            var aRect = this.getPageBox( {nPage: p} );
            var width = aRect[2] - aRect[0];
            var fieldCreated = false;

            if (width == (11*inch))
            {
                aRect[0] += 1.1*inch;
                aRect[2] = aRect[0] - 36;
                aRect[1] -= 16.6*inch;
                aRect[3] = aRect[1] + 1*inch;

                newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
                newDateField.rotation = 270;
                fieldCreated = true;
            }

            if (width == (17*inch))
            {
                aRect[0] += 15.57*inch;
                aRect[2] = aRect[0]+1*inch;
                aRect[1] -= 9.875*inch;
                aRect[3] = aRect[1] - 36;

                newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
                fieldCreated = true;
            }

            if (width == (24*inch))
            {
                aRect[0] += 1.8*inch;
                aRect[2] = aRect[0] - 36;
                aRect[1] -= 34.9*inch;
                aRect[3] = aRect[1] + 1.75*inch;

                newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
                newDateField.rotation = 270;
                fieldCreated = true;
            }

            if (width == (36*inch))
            {
                aRect[0] += 33.17*inch;
                aRect[2] = aRect[0]+1.75*inch;
                aRect[1] -= 22.2*inch;
                aRect[3] = aRect[1] - 36;

                newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
                fieldCreated = true;
            }

            if (fieldCreated)
            {
                newDateField.textColor = color.red
                newDateField.value = util.printd("mm/dd/yy", oCurrentDate) + " " + util.printd("HH:MM", oCurrentDate) + " " + newVersionLetter;
                newDateField.readonly = true;
            }   
        }
    }
}
4

1 回答 1

2

您是否尝试过从页面获取页面旋转值,然后根据返回值调整图章的方向?

根据Acrobat 文档第 127 页。

getPageRotation 将根据页面的旋转方式返回 0、90、180 或 270。然后您可以使用该值来调整图章的位置。

var rotation = this.getPageRotation(3); //get rotation of page 3
if(rotation)
{
    //Depending on the value, adjust location of stamp
}
于 2015-03-17T21:28:58.970 回答