简体   繁体   English

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

[英]Set PDF page layout to “TwoPageLeft” using JavaScript (Acrobat Pro)

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). 我想更改(或添加,如果它不存在)到具有多页的PDF文件,该设置将强制以两页模式(例如PageLayout:TwoPageLeft)打开PDF。 I tried with that kind of JavaScript (given with Enfocus FullSwitch as example) : 我尝试了这种JavaScript(以Enfocus FullSwitch为例):

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} );
}
}

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). 但这并没有达到我想要的效果(它将与Acrobat Pro一起打开并保存为新文件,而不包括布局的设置)。

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? 有谁能帮助我更正该代码,以使JS打开PDF文件,设置PDF数据内的布局并将其保存?

The readable information inside the PDF file should looks like this: PDF文件中的可读信息应如下所示:

PageLayout/TwoPageLeft/Type/Catalog/ViewerPreferences

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. 有关信息,我正在使用FullSwitch(Enfocus)通过Acrobat Pro处理工作流中的文件,目前,它仅保存文件而不添加设置。

I can't find myself the answer over all the Web I searched recently, so I ask… 我找不到自己在最近搜索的所有Web上的答案,所以我问…

Thanks in advance! 提前致谢!

I think you copied the "this.layout = ..." line out of the Acrobat JavaScript reference documentation, correct? 我认为您从Acrobat JavaScript参考文档中复制了“ this.layout = ...”行,对吗?

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. 当您编写JavaScript以供Switch执行(或者让Switch指示Acrobat为您执行)时,应使用“ $ doc”变量来引用Switch正在处理的文档。

So try changing the line: 因此,请尝试更改行:

$this.layout = "TwoColumnLeft";

to

$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. 此处建议的更改将在您要查找的文档中进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM