Link to home
Start Free TrialLog in
Avatar of Thamesditton
Thamesditton

asked on

How do I spilt individual PDF pages into two

I have been sent a PDF file. It consists of 18 pages of what should be double page spreads in a landscape format. I would like to split them straight down the middle to create 36 pages. How do I do this please?

Thanks, in advance.
Avatar of BigBadWolf_000
BigBadWolf_000
Flag of United States of America image

You could write a JavaScript program that duplicates every page and then sets the crop boxes so that on the first page of every page pair, the left side gets selected via the crop box, and on the second page it would be the right side. Do you have any experience with JavaScript programming for Acrobat?
Avatar of Thamesditton
Thamesditton

ASKER

Unfortunately I do not have experience with JavaScript programming for Acrobat. I was hoping there was a quick and idiot-proof way of doing it.
Let's see... Save the script to a file and copy it to C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts (or whatever your version number is). This will create a new menu item under teh Document menu named "Split Pages". Give it a try and see if it works for you.
ProcessDocument = app.trustedFunction(function()
{
    // create a new document
    app.beginPriv();
    var newDoc = app.newDoc();
    app.endPriv();
 
    // get the filename of our current file
 
    var i = 0;
    while (i < this.numPages)
    {
        newDoc.insertPages( {
            nPage: newDoc.numPages-1,
            cPath: this.path,
            nStart: i
        });
        newDoc.insertPages( {
            nPage: newDoc.numPages-1,
            cPath: this.path,
            nStart: i
        });
        // we did this twice so that we can then split each copy of the page into a left
        // and right half.
        i++;
    }
 
    if (newDoc.numPages > 1)
    {
        newDoc.deletePages(0);  // this gets rid of the page that was created with the newDoc call.
    }
 
    // at this point we have a documnent with every page from the source document
    // copied twice
 
 
    for (i=0; i<newDoc.numPages; i++)
    {
        // determine the crop box of the page
        var cropRect = newDoc.getPageBox("Crop", i);
        var halfWidth = (cropRect[2]-cropRect[0])/2;
 
        var cropLeft = new Array();
        cropLeft[0] = cropRect[0];
        cropLeft[1] = cropRect[1];
        cropLeft[2] = cropRect[0] + halfWidth;
        cropLeft[3] = cropRect[3];
 
        var cropRight = new Array();
        cropRight[0] = cropRect[2] - halfWidth;
        cropRight[1] = cropRect[1];
        cropRight[2] = cropRect[2];
        cropRight[3] = cropRect[3];
 
        if (i%2 == 0)
        {
           newDoc.setPageBoxes( {
               cBox: "Crop",
               nStart: i,
               rBox: cropLeft
               });
        }
        else
        {
           newDoc.setPageBoxes( {
               cBox: "Crop",
               nStart: i,
               rBox: cropRight
               });
        }
    }
}
)

Open in new window

Sorry, forgot one very important piece of information: The filename that ou use must have the .js extension (e.g. SplitPages.js) - otherwise Acrobat will not recognize the file as a JavaScript file.
I'm really sorry. I followed your instructions. I am using Adobe Acrobat Pro 8, but 'Split Pages' is not appearing in the Document menu.
Can you please bring up the JavaScript console (ctrl-J) - do you see any error messages? You may have to allow a JavaScript to add a menu item by going into Acrobat's Preferences, then select the JavaScript category and make sure that "Enable menu items JavaScript execution privileges" is set - of course, "Enable Acrobat JavaScript" also needs to be checked.
No bugs showing up. Preferences checked as suggested, but still no luck I'm afraid. I've tried restarting again a few times to, just in case.
What's the filename that you've used? How did you create the file (you need to use a text editor like Notepad)?
 
I've used Notepad and saved it as Split Pages.js
Encoding is ANSI
Try removing the space in the file name.
Still no luck. Perhaps I should try it on a different computer? Many thanks for trying though!
That's odd... If Acrobat recognizes the file, you should get an error message. What OS and version are you using?
Windows XP using Adobe Acrobat 8 Professional - part of the CS3 bundle.
Screen-Cap-Experts-Exchange.JPG
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might be on to something. When I save it it just shows as SplitPages.js albeit with a .txt image icon.
Fantastic! You solved it. I opened the file in Dreamweaver and saved as a .js and it works perfectly now. You really do deserve your Genius rank! Thank you so much.
Thank you, so very much for all your time and a fantastic solution.
That is one of the things that I really hate about Windows: The default is to not show file extensions. you can change that by bringing up your file explorer (e.g. double-click on the My Computer icon), then select "Tools>Folder Options..." Go to the "View" tab and deselect "Hide extesions for known file types", then click on the "Apply to All Folders" buttons. From now on you will know if you are working with a JS file or a TXT file.
I was looking for something to do the same thing - split a .pdf file in half. This plugin seems to be what I need. While I was able to copy it and install it in the proper directory, and it appears on the document menu of Acrobat 9 Pro, when I try to run it on a document, it gives me the error message,

"An internal error occurred"

Any ideas? Thanks!
Did you check the JavaScript console (ctrl-J)?
That was it! (And I even read the thread twice - shame on me). What a GREAT plugin - thank you VERY much!
It's actually not a plug-in. Plug-ins are written in C++, and linked into Acrobat at run time. This is just a small JavaScript program.
First a little comment: the script from post nr 24013721 won't register the command in the Document menu, because the app.addMenuItem command is missing.

Then, I've tried the downloaded script, but I get an error popup: "An internal error occured".

The JavaScript console shows:
GeneralError: Operation failed.
Root.(null):21:Menu splitPagesJS:Exec
script terminated
The problem seems to be in the loop (lines 11 and 37 in the original scripts). The loop gets executed once, and then throws the above error.

I tried several things. Replaced the this.numPages variable with a constant ("15" for a 15-page document, or even just "2" for testing), replaced the "while" loop with a "for" loop (integrating the variable initialization and increment into the "for" command). But keep on getting the same error.

If I remove both of the loops and manually copy the commands 15x for copying and 30x for trimming a 15-page document, then everything is ok!

I am so confused, I know quite a bit JavaScript, but can Acrobat have problems with while and for loops? It's not in the variables, because replacing them with the approriate constants doesn't help...

Using Acrobat Pro 8 on Windows XP.
pbb - this question is already closed - and you are not the original author, please post a new (related) question. If you post a link to the new question here, I'll take a look.