Export PDF from indesign, name of file with page number

Hello i’m currently writing a script to export PDF’s or EPS (depending on the RIP it going to) from Indesign CS5 with specific settings.

  • The user will input the page range he wants to export (in a dialog window), in the case of PDF when the user input will be (All), I want to create a PDF for each page separately and the name of these PDF will end by the page number in a 3 digits number. Same thing if he exports only one page, or pages here and there (ex. 26,52,53,96).

  • So my question is, is there a way to export separately when exporting more than one page or it has to be done with a repeat command?

  • For the naming of the files, can I get the page number that Indesign is currently exporting?

Thanks
I will probably have other questions later relating this thread.
:slight_smile:

Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)

To both your questions. yes. I’ve done something somewhat similar before.

Do you have bugs with parts of your script? How does it look so far?

I’m just beginning, i write down on paper right now how I’m gonna build that cause is other stuff that comes with it. In applescript I juste did the beginning…

tell application "Adobe InDesign CS5"
	set MyDocument to active document
	set PDFPreset to "RampageCMYK" as string
	set MyPDFexportPreset to PDF export preset PDFPreset
	set MyPath to file path of MyDocument as string
	set MyPages to text returned of (display dialog "Quelles pages voulez-vous exporter" default answer "All" as text)
	set MyFolder to choose folder with prompt "Dossier de sauvegarde de vos fichiers:" default location alias MyPath
	
	tell MyDocument
		export format PDF type to (MyPath as string) & (name of MyDocument as string) & ".pdf" using MyPDFexportPreset without showing options
	end tell
	
end tell

This is what I currently use to export all the pages as individual PDFs, you can easily modify it to fit your needs:

with timeout of 3600 seconds
–script de Stéphane Cyr
–ce script exporte chaque page d’un document InDesign ouvert en PDF individuel
set my_destination to (choose folder with prompt “Choose destination for the PDFs”) as string
tell application “Adobe InDesign CS5.5”
activate
–les 2 lignes suivantes servent à sélectionner le PDF preset à utiliser
set my_pdf_export to get the name of every PDF export preset
set my_pdf_choice to (choose from list my_pdf_export) as string

	repeat with this_doc in (get every document)
		set this_page to 1
		set doc_name to get name of this_doc
		if doc_name contains "indd" then set doc_name to (characters 1 thru -6 of doc_name)
		set page_count to count every page of document 1
		repeat page_count times
			set my_page_range to this_page as string
			set doc_name_page to doc_name & "-" & this_page & ".pdf"
			tell PDF export preferences
				set page range to my_page_range
				
				tell this_doc
					export format PDF type to my_destination & doc_name_page using my_pdf_choice without showing options
					set this_page to this_page + 1
					
				end tell
			end tell
		end repeat
	end repeat
	--pour remettre les préférences de page à "all"
	tell PDF export preferences
		set page range to all pages
	end tell
end tell

end timeout

Merci je devrais être correct pour l’arranger à ma guise.

It’s ok if I want to export all the pages in the document, but if the user inputs (1,6,9,12) in the page range??? I have not enough experience in scripting to figure this thing out!

I figured it out but just in my head! I can’t write it down! here it is (I’ll need somebody to help me writing the right things…)

set MyPages to (display dialog "Quelles pages voulez-vous exporter" default answer "All")

The user will input (e.g. 4,6,7,11)
each numbers can be in a list in with each number is an item

then you make a repeat routine using each item in the list as reference to page numbers.

e.g.

repeat with ...  in .... (actually not very good in repeats...)
tell PDF export preferences
set page range to (item in the list)
end tell

tell MyDocument
			export format PDF type to (MyPath as string) & (name of MyDocument as string) & (Item in the list) & ".pdf" using MyPDFexportPreset without showing options
		end tell
	end repeat
end tell 

I don’t if it’s clear…

Any help appreciate
Thank you

Then this code should work since it allows you to choose to export “all pages” or just the ones you need:


with timeout of 3600 seconds
	--script de Stéphane Cyr
	--ce script exporte chaque page d'un document InDesign ouvert en PDF individuel
	
	--pour choisir où seront exportés les PDFs
	set my_destination to (choose folder with prompt "Choisir la destination des PDFs") as string
	
	tell application "Adobe InDesign CS5.5"
		activate
		--les 2 lignes suivantes servent à sélectionner le PDF preset à utiliser
		set my_pdf_export to get the name of every PDF export preset
		set my_pdf_choice to (choose from list my_pdf_export) as string
		
		--début de la première boucle servant à déterminer le nombre de fichiers InDesign actifs
		repeat with this_doc in (get every document)
			set my_page_list to {"all pages"}
			set doc_name to get name of this_doc
			tell this_doc to set my_page_list to my_page_list & (get the name of every page)
			
			--pour choisir les pages à imprimer, la touche "CMD" permet les sélections multiples
			choose from list my_page_list with prompt "Choisir pages à imprimer pour le document: " & doc_name with multiple selections allowed
			set my_choice to the result
			
			--si "all pages" est choisi dans la liste, chaque page sera exportée individuellement
			if my_choice is {"all pages"} then set my_choice to (items 2 thru -1 of my_page_list)
			
			if doc_name contains "indd" then set doc_name to (characters 1 thru -6 of doc_name)
			
			--début de la deuxième boucle servant exporter les pages du PDF visé par la première boucle
			repeat with this_page in my_choice
				set my_page_range to this_page as string
				set doc_name_page to doc_name & "-" & this_page & ".pdf"
				tell PDF export preferences
					set page range to my_page_range
					
					tell this_doc
						export format PDF type to my_destination & doc_name_page using my_pdf_choice without showing options
					end tell
				end tell
			end repeat
			--fin de la deuxième boucle
		end repeat
		--fin de la première boucle
		
		--pour remettre les préférences de page à "all pages"
		tell PDF export preferences
			set page range to all pages
		end tell
	end tell
end timeout

Merci :slight_smile:

J’ai maintenant tout les outils pour accomplir ce que je veux faire.

Thanks for the share.