在Adobe Acrobat中检测旋转的页面

时间:2015-03-14 18:01:45

标签: adobe acrobat adobe-javascript

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

我解决了大部分问题,但有一个问题。当此人在最终方向创建PDF页面(来自CAD程序)时,我的代码(如下)可正常工作。但是,如果他们创建一个页面作为横向,然后使用'旋转页面' Adobe 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;
            }   
        }
    }
}

1 个答案:

答案 0 :(得分:2)

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

Acrobat Documentation页面。

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
}