将 PDF 页面布局设置为“TwoPageLeft"使用 JavaScript (Acrobat Pro)

将 PDF 页面布局设置为“TwoPageLeft

问题描述:

我想更改(或添加,如果它不存在)具有多页的 PDF 文件,该设置将强制以两页模式打开 PDF(例如 PageLayout : TwoPageLeft).我尝试使用那种 JavaScript(以 Enfocus FullSwitch 为例):

I would like to change (or add if it doesn't exist) to a PDF file with multiple pages the setting that will force the PDF to be opened in two page mode (PageLayout : TwoPageLeft for example). I tried with that kind of JavaScript (given with Enfocus FullSwitch as example) :

if(($error == null) && ($doc != null))
{
try
{
    $outfile = $outfolder + '/' + $filename + ".pdf";
    $doc.layout = "TwoPageLeft";
    $doc.saveAs( {cPath : $outfile, bCopy : true});
    $outfiles.push($outfile);
}
catch(theError)
{
    $error = theError;
    $doc.closeDoc( {bNoSave : true} );
}
}

但它不能如我所愿(它将使用 Acrobat Pro 打开并另存为新文件,而不包括有关布局的设置).

But it doesn't work as I would like (it will be opened with Acrobat Pro and saved as a new file without including the setting about the layout).

谁能帮我改正那个代码,让JS打开PDF文件,在PDF数据里面设置布局并保存?

Does anyone can help me to correct that code to let JS open the PDF file, set the layout inside the PDF datas and save it out?

PDF 文件中的可读信息应如下所示:

The readable information inside the PDF file should looks like this:

PageLayout/TwoPageLeft/Type/Catalog/ViewerPreferences

有关信息,我正在使用 FullSwitch (Enfocus) 处理工作流中的文件,使用 Acrobat Pro,而此时,它仅保存文件而不添加设置.

For information, I'm using FullSwitch (Enfocus) to handle files in a workflow, with Acrobat Pro, and at this time, it's only saving the file without adding the setting.

我在最近搜索的所有网络中都找不到答案,所以我问......

I can't find myself the answer over all the Web I searched recently, so I ask…

提前致谢!

我认为您从 Acrobat JavaScript 参考文档中复制了this.layout = ..."行,对吗?

I think you copied the "this.layout = ..." line out of the Acrobat JavaScript reference documentation, correct?

当您编写 JavaScript 以供 Switch 执行(或者更确切地说是让 Switch 指示 Acrobat 为您执行)时,您应该使用$doc"变量来引用 Switch 正在处理的文档.

When you write a JavaScript for Switch to execute (or rather for Switch to instruct Acrobat to execute for you), you should use the "$doc" variable to refer to the document Switch is processing.

所以尝试改变行:

$this.layout = "TwoColumnLeft";

$doc.layout = "TwoColumnLeft";

正如您所说,其余代码有效并且文档保存没有错误,我认为您的其余代码是正确的.此处建议的更改将在您要查找的文档中进行调整.

As you say the rest of the code works and the document is saved without errors I assume the rest of your code is correct. The change proposed here will make the adjustment in the document you're looking for.