如何编写javascript来重新排序pdf文档的页面? [英] How to write javascript to reorder pages of a pdf document?

查看:106
本文介绍了如何编写javascript来重新排序pdf文档的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双面文档作为两个单独的pdf文件 - 一个文档中的前向页面和第二个中的后向页面。

I have a double-sided document as two separate pdf files — front-facing pages in one document and rear-facing pages in the second.

front.pdf
rear.pdf

我还将它们组合成一个包含所有页面的单个文档,但在后向页面之前包含所有前向页面。页面排序的形式为 {1,3,5,7,...,[n],2,4,6,8,...,[n-1 OR n + 1]}

I have also combined them into a single document with all the pages but with all the front-facing pages before the rear-facing pages. The page ordering is of the form, {1,3,5,7,...,[n],2,4,6,8,...,[n-1 OR n+1]}

all.pdf

我希望编写一个可以在Adobe Abrobat X Pro中运行的简单JavaScript。理想情况下,它会计算文档的页面 all.pdf ,处理两个总页数奇数或偶数的情况,然后对它们进行重新排序,使它们成为按原始顺序:

I wish to write a simple javascript that can be run from inside Adobe Abrobat X Pro. Ideally, it would count the pages of the document all.pdf, handle both occasion when there are either an odd or even number of total pages and then reorder them such that they are in their original order:

page [1>3>4>2] => page [1>2>3>4]

以上微小的主要代码片段来自答案在这个问题上的SuperUser上 user171577 https:// superuser.com/questions/181596/software-that-merges-pdf-every-other-page

The tiny leading code snippet above is from the answer by user171577 on SuperUser in this question: https://superuser.com/questions/181596/software-that-merges-pdf-every-other-page

推荐答案

我能够通过NullUserException完成以下建议:

I was able to accomplish this following advice from NullUserException :

此脚本需要一个由所有奇数页组成的文档,后跟所有偶数页。它将处理 n 偶数页面和 n + 1 奇数页面的情况。

This script requires a document composed of all the odd pages followed by all the even pages. It will cope with cases where there are n even pages and n+1 odd pages.

我输入了一个名为 InterleavePages 的'文档JavaScript',代码如下:

I entered a 'Document JavaScript' called InterleavePages, with the following code:

function InterleavePages() {

var n = this.numPages;
var nOdd = Math.floor(n / 2);
var nEven = n - nOdd;
var x;
var y;
var i;

for(i = 0; i < nEven; i++) {
                         // movePage x, toAfterPage y
                         // note page numbers are 0-indexed
    x = nOdd + (i);      //
    y = i * 2     ;      //  
    this.movePage(x,y); 
   }
}
InterleavePages();

这篇关于如何编写javascript来重新排序pdf文档的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆