tryting to combine two pdf's into one using join.py

Hi all
I am using the below code which I thought would combine two selected pdf’s into one and have it presented as output.pdf, it produces the final pdf but only as single page not combined selected pdf’s as I would have thought it would.

Could some one point me in the right direction to be able to combine two pdf’s into one please.

choose file with multiple selections allowed
do shell script "python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '/Users/BUDGIE/Desktop/FILES/output.pdf'"

Here is a script borrowed to Shane STANLEY doing the job.
As is it requires Yosemite or El Capitan.

use scripting additions
use framework "Foundation"
use framework "Quartz" -- required for PDF stuff

set inFiles to (choose file of type {"pdf"} with prompt "Choose your PDF files:" with multiple selections allowed)
set destPosixPath to POSIX path of (choose file name default name "Combined.pdf" with prompt "Save new PDF to:")
its combineFiles:inFiles savingTo:destPosixPath

on combineFiles:inFiles savingTo:destPosixPath
	--  make URL of the first PDF
	set inNSURL to current application's class "NSURL"'s fileURLWithPath:(POSIX path of item 1 of inFiles)
	-- make PDF document from the URL
	set theDoc to current application's PDFDocument's alloc()'s initWithURL:inNSURL
	-- loop through the rest
	set oldDocCount to theDoc's pageCount()
	set inFiles to rest of inFiles
	repeat with aFile in inFiles
		--  make URL of the next PDF
		set inNSURL to (current application's class "NSURL"'s fileURLWithPath:(POSIX path of aFile))
		-- make PDF document from the URL
		set newDoc to (current application's PDFDocument's alloc()'s initWithURL:inNSURL)
		-- loop through, moving pages
		set newDocCount to newDoc's pageCount()
		repeat with i from 1 to newDocCount
			-- get page of old PDF
			set thePDFPage to (newDoc's pageAtIndex:(i - 1)) -- zero-based indexes
			-- insert the page
			(theDoc's insertPage:thePDFPage atIndex:oldDocCount)
			set oldDocCount to oldDocCount + 1
		end repeat
	end repeat
	set outNSURL to current application's class "NSURL"'s fileURLWithPath:destPosixPath
	-- save the new PDF
	(theDoc's writeToURL:outNSURL)
end combineFiles:savingTo:

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) jeudi 17 septembre 2015 10:36:22

thank you Yvan for putting me onto this, and thank you Shane the code is excellent :smiley:

way more complicated than I thought, also I found using what I had even with it only producing
one pdf, that the pdf produced was blank, quite strange…

cheers

– Hi, this works in Mavericks:


property join_py : quoted form of "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"

on run
	set dragged_files to (choose file with prompt "Select multiple files with Command-click" with multiple selections allowed)
	open dragged_files
end run

on open (dragged_files)
	
	set add_pdfs to ""
	set output_pdf to POSIX path of ("HD:combined.pdf" as Unicode text)
	
	repeat with an_item in dragged_files
		set add_pdfs to add_pdfs & space & quoted form of (POSIX path of (an_item as alias))
	end repeat

	do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & add_pdfs
	
end open

The script isn’t complicated.
It’s a ready to use piece of code.

What I don’t understand is how it was able to build a blank file.
Of course, I assume that
(1) you extracted the script by a double click on the dedicated button in the message window
(2) you selected at least two PDF files in the choose file dialog.

As it is on my machine for several month, I took care to apply it to : AppleScript Language Guide.pdf, Everyday ASObjC.pdf and a three pages personal PDF. In a snap I had the Combined.pdf file on the desktop and of course I checked that everything was correctly passed.

Honestly, I’m more at ease with such script than I am with a Python one for which I am completely dependent of what somebody else wrote which I am unable to edit by myself.
To be honest, I asked Shane’s help numerous times but now, I am able to edit several of the scripts which he posted here and there.

My original attempt was made in 10.10.5. I just made an other one in El Capitan GR and I got a 350 pages PDF in a snap.

Yvan KOENIG running El Capitan 10.11 in French (VALLAURIS, France) jeudi 17 septembre 2015 23:15:49

sorry Yvan, yes Shane’s code is perfect, I was refering to the code I had, and that it was producing a blank pdf, not Shane’s.

Thank you kerflooey for your code also, works like a charm, I am still baffled as to why I got a blank page from mine

cheers gents

Probably because you did nothing with the result of your choose file command – there are no source documents specified.