Wednesday, May 22, 2019

#1 2019-03-14 02:08:43 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 125

Split PDF on single page PDFs

Hi, everybody.

Exists on net one nice solution for this task (works perfect, using Automator and Preview):

Step 1: Download that workflow (clickable reference).

Step 2: Move this workflow from Downloads folder to ~/Library/Services.

What did you just do? You have created a new service for your PDF files!!! To use it, select any of your PDF files, right click on it and select Services ---> Split PDF.

This service breaks clicked PDF on single pages (NOTE: AND STORES THEM IN SAME FOLDER), therefore, I recommend you to create a new folder and move PDF into it before breaking. Just to keep order on your computer.

Last edited by KniazidisR (2019-03-14 02:16:27 pm)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#2 2019-03-28 10:48:54 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 125

Re: Split PDF on single page PDFs

Greetings to all the scripters. In the post above, I showed, how to split PDF into separate pages using the "Split PDF" action built into Automator. Now I will show you something much better.

Although the service from Apple is not bad, it has a significant drawback: Apple application "Preview" is used to divide PDF into pages only as pictures. That is, you get at the output PDFs without recognized text and without the ability to search for words and phrases. Therefore, we will create our own custom service "Split PDF", and send the native one from Apple to a well-deserved rest.

For OCR text recognition we will use Infix PDF Editor. Why do I choose this software? After all, the Mac version of this application does not exist... The thing is that I still cannot find more convenient and correct software for processing PDF in text mode. In addition, this software easily divides PDF into pages, saving fonts, forms and all that we need (unlike Preview).

All the rest are either much more expensive (Acrobat), or violate the format, or have a stupid user interface. So what do we do? We just install this great program through Crossover. If you still don’t have a Crossover, I’m sorry for you, and you don’t have anything to do with your computer at all. Just get these 2 programs, if you want to work with PDF easily and pleasantly, here is my advice. I note that if someone prefers Acrobat, this guide will serve as an example for creating such a service using Acrobat.

So, you have on your computer 2 programs suggested above. Now, we turn to the real work - to create a custom service.

1) Open Automator
2) In the window that pops up, highlight Service and then hit Choose.
3) Now in the Library section on the left, click on Utilities and then find Set Value of Variable. Drag it to the main window on the right.
4) In the Variable dropdown, choose New variable… and call it original_PDFs
5) In the Service receives selected choose PDF files
6) Set the in dropdown to Finder
7) Still in the Utilities section of the Library on the left, find Run AppleScript. Drag it to the main window under our last step.

Opens shell-script:


on run {input, parameters}
   
    (* Your script goes here *)
   
    return input
end run


8) Replace (* Your script goes here *) with our script lines:

Applescript:


set myPDF to input

-- replace the path in this code line with your path to the utility "MouseTools".
   set mouseToolsPath to alias "Χωρίς τίτλο:Users:123:Applications:MouseTools"
   
   -- Here we get the name of window 1 of the selected PDF
   set myPosixPath to POSIX path of myPDF
   set myWindowName to (do shell script ("basename " & quoted form of POSIX path of myPosixPath)) & " - Infix Pro"
   
   -- This string is needed only for shorten the code and increase its speed
   set myString to quoted form of POSIX path of mouseToolsPath & " -x "
   
   -- Open the PDF in Infix PDF Editor
   tell application "Infix PDF Editor"
       activate
       open myPDF
   end tell
   
   -- Open the main window in "full screen" mode
   tell application "System Events"
       tell application process "Infix PDF Editor"
           repeat until (window myWindowName exists)
               delay 0.1
           end repeat
           tell window myWindowName
               click button 2
           end tell
       end tell
   end tell
   
   -- Click the menu "Pages", then click menu item "Extract" of menu "Pages" of Infix PDF Editor
   tell application "System Events"
       tell application process "Infix PDF Editor"
           repeat until (window myWindowName exists)
               delay 0.1
           end repeat
           delay 0.5
           do shell script myString & "195 -y 15 -leftClick"
           repeat until (window "Extract Pages" exists)
               do shell script myString & "225 -y 119 -leftClick"
               delay 0.1
           end repeat
       end tell
   end tell

9) Go to File > Save and give your new service a name. I’ll call mine Split_PDF.

You have just created a Service. This means that if you right-click anybody PDF, you can see service Split_PDF and use it.

Note 1): I had to use a third-party utility MouseTools, since getting access to the menu items of the Infix PDF Editor inside the Crossover was not an easy task. Do not forget to replace the path in the code line set mouseToolsPath to alias "Χωρίς τίτλο:Users:123:Applications:MouseTools" with your path to this utility.

Note 2): UI scripting for similar service using Adobe pdf  editor is much easier.

Note 3): You can save script in step 8) as applet and use it by clucking application icon. The only you need is replacing code line set myPDF to input with that:

set myPDF to choose file of type {"pdf"}

Last edited by KniazidisR (2019-03-30 09:30:29 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)