在 Adob​​e Acrobat 中检测旋转的页面

Detecting rotated pages in Adobe Acrobat

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

我已经解决了大部分问题,但有一个问题。当此人以最终方向创建 PDF 页面(从 CAD 程序)时,我的代码(如下)可以正常工作。但是,如果他们将页面创建为横向,然后使用 Adob​​e Acrobat 中的 'rotate page' 功能使其显示为纵向,则图章显示在正确的位置,但与我想要的方向偏离 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;
            }   
        }
    }
}

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

根据 Acrobat Documentation 第 127 页。

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

var rotation = this.getPageRotation(3); //get rotation of page 3
if(rotation)
{
    //Depending on the value, adjust location of stamp
}