PDF page count, cut, copy, rename ...

Hi There,
i have a problem … i can’t script :frowning:

is it possible to:
check PDF pages in “Binder A”, if pdf pages is divisible by 4 with even number than move to “Binder B”
if not extract and delete the first 2 and the last 4 pages, rename the file and move this 6 pages to “Binder C”, rename the residue of the pdfs an move it to “Binder B”

hope you can help me and understand my prob …

thanks :wink:

I apologize but, what to do if the original PDF contains 3, 4, 5, 6 pages ?
With 3, 4 or 5 it will be difficult to extract 2 + 4 = 6 pages

Yvan KOENIG (VALLAURIS, France) mardi 2 septembre 2014 16:03:11

Also what application are you targetting? Do you wish to script Acrobat? What version? Or any other app? Which one?

Hi Yvan! I guess the PDF to work on always have more than 6 pages, I would even say much more. I can understand your point of view but if the OP does not evoke such cases than I guess he knows about his files. But for a neat AppleScript script, any case should be considered, even a file say thrown on an applet that would not be a PDF file. Than I suppose those cases must be handled (write a report or so) or just ignored.

Hi there,

PDF’s have minimum 10 Pages - its for my workflow with CtP sometime i have a 6 Page Cover, sometimes a 4 Page Cover … and every day 4 till 10 files :frowning:

I would like to use Acrobat Pro X, it can extract and delete, manually at least :wink:

Since you’re saying you cannot script, the first step to go is to read some existing (simple) scripts and see if you get sth. AS language is quite “natural” (at least for English speakers I guess :)).
The main thing to keep in mind is that you’ll want to talk to applications, using events (typically verbs) to act on some objects. Any scriptable application has its own vocabulary (although some vocabulary is common to every applications, such as count, delete, copy, etc.). You’ll “learn” an application vocabulary by opening its dictionary via an Script editor (Script Debugger, AppleScript Editor or so). It is also very important to consider the syntax. As your code has a syntax error it won’t compile and you’ll not be able to run it. Sometimes the syntax is correct but other issues come up.

Another possibility to enter the scripting world is to record actions (make a new script in ASE) and click the Record button, then perform some actions in the Finder. Back in ASE you’ll see those actions coded in AS language.
This said, I think Adobe also have that possibility to recording actions.

Be aware that a scriptable application does not mean that any action you can perform manually is necessarily scriptable while the opposite is also right: you can sometimes perform actions or reach some data you cannot in the real world of the app.

I know this still not answer your question but I think it’s important to keep that in mind prior any further step into AppleScript scripting.

EDIT - What Adobe Acrobat Pro X documentation reads about actions: http://goo.gl/VvzYNs You’ll probably find sth helpful investigating a bit further.
Also: https://www.evermap.com/javascript.asp#5.%20How%20to%20create%20a%20batch%20sequence%20with%20JavaScript%20code?
And: http://www.pdfscripting.com/public/department35.cfm
And: http://acrobatusers.com/tutorials/actions-macros-acrobat-x
All of these are JavaScript related which is the easiest way of creating actions for Acrobat. If you really need some AppleScript help just let us know. (This page could be a good starter: http://xprepress.com/dealing-acrobat-applescript/).

thanks for help …

i think it works good :wink:

set the_pdf_file to choose file of type {"com.adobe.pdf"} with prompt "Preisliste auswählen:"
set jobIDDialog to (display dialog "Auftragsnummer" default answer ¬
	"AU-" buttons ¬
	{" OK "})
set JobID to text returned of jobIDDialog


tell application "Finder"
	set file_name to get name of the_pdf_file
end tell

tell application "Adobe Acrobat Pro"
	try
		open the_pdf_file with invisible
	on error
		display alert "Kann die Datei nicht öffnen" & file_name
		return false
	end try
	set numPages to number of pages of document 1
	numPages
	if numPages mod 4 is not 0 then
		tell application "Adobe Acrobat Pro"
			
			--COVER--
			set docRef to document 1
			set docName to name of document 1
			set PageCount to page count
			set PageCountbeginn to PageCount - 4
			delete pages docRef first 3 last PageCountbeginn
			--Speicher die Datei in COVER als COVER--
			mount volume "smb://appserv01/PLumschlag/"
			set volCover to "PLumschlag:" as text
			set NeuePdf to (JobID & " " & "Umschlag--" & docName as string)
			set NeuePdfsave to ((volCover) & JobID & " " & "Umschlag--" & docName as string)
			save docRef to file NeuePdfsave
			close document 1
			--INHALT--
			open the_pdf_file with invisible
			set docName to name of document 1
			set PageCount to page count
			set PageCountbeginnInhalt to PageCount - 3
			delete pages docRef first PageCountbeginnInhalt last PageCount
			delete pages docRef first 1 last 2
			--Speicher die Datei in INHALT als INHALT
			mount volume "smb://appserv01/PLinhalt/"
			set volOhneKlapper to "PLinhalt:" as text
			set NeuePdf to ((volOhneKlapper) & JobID & " " & "INHALT--" & docName as string)
			save docRef to file NeuePdf
			close document 1
			
			tell application "Finder"
				eject disk "PLinhalt"
				eject disk "PLumschlag"
			end tell
			
		end tell
	else
		
		
		tell application "Adobe Acrobat Pro"
			set docRef to document 1
			set docName to name of document 1
			mount volume "smb://appserv01/PLinhalt/"
			set volOhneKlapper to "PLinhalt:" as text
			set NeuePdf to ((volOhneKlapper) & JobID & " " & "komplett--" & docName as string)
			save docRef to file NeuePdf
			close document 1
		end tell
		
		tell application "Finder"
			eject disk "PLinhalt"
		end tell
		
	end if
end tell