🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18914

Here's a script for exporting selected objects to PDF

#18914
From: Richard Ronnback
Date: Sat, 01 Feb 2003 11:26
69 lines
3965 bytes
In my struggle to learn some scripting I just made a script to export selected objects to a PDF-file. In case anyone wants it, here it is:



 
tell application "InDesign 2.0.1" 
	try 
		if class of selection is in {text, character, word, line, text column, paragraph, text style range, insertion point, table, guide} then 
			display dialog "Please select at least one object before you run this script" 
		else 
			set MyPDF to (choose file name with prompt "Save PDF file as:") as string

			--this section is used to store some values so that they later can be reset 
			set myOldMarginTop to margin top of margin preferences 
			set myOldMarginBottom to margin bottom of margin preferences 
			set myOldMarginLeft to margin left of margin preferences 
			set myOldMarginRight to margin right of margin preferences 
			set myOldColumnCount to column count of margin preferences 
			set myOldHeight to page height of document preferences 
			set myOldWidth to page width of document preferences

			--this section gets the width and height of the selected items and copies them to the clipboard 
			set mySelection to items of selection 
			if (count of mySelection) is greater than 1 then 
				tell active document 
					set myGroup to make group with data mySelection 
					set myHeight to (item 3 of geometric bounds of myGroup as number) - (item 1 of geometric bounds of myGroup as number) 
					set myWidth to (item 4 of geometric bounds of myGroup as number) - (item 2 of geometric bounds of myGroup as number) 
					tell application "InDesign 2.0.1" 
						copy 
					end tell 
					tell active document 
						ungroup myGroup 
					end tell 
				end tell 
			else 
				set myHeight to (item 3 of geometric bounds of selection as number) - (item 1 of geometric bounds of selection as number) 
				set myWidth to (item 4 of geometric bounds of selection as number) - (item 2 of geometric bounds of selection as number) 
				copy 
			end if

			-- this section creates a new document, paste the content of the clipboard and exports as PDF 
			set margin top of margin preferences to 0.0 
			set margin bottom of margin preferences to 0.0 
			set margin left of margin preferences to 0.0 
			set margin right of margin preferences to 0.0 
			set column count of margin preferences to myOldColumnCount 
			set properties of document preferences to {page height:myHeight, page width:myWidth}

			set myDocument to make new document 
			tell myDocument 
				paste 
				export format PDF type to MyPDF using "[eBook]" with showing options 
				close without saving 
			end tell

			--this section restores the original values 
			set properties of document preferences to {page height:myOldHeight, page width:myOldWidth} 
			set margin top of margin preferences to myOldMarginTop 
			set margin bottom of margin preferences to myOldMarginBottom 
			set margin left of margin preferences to myOldMarginLeft 
			set margin right of margin preferences to myOldMarginRight 
			set column count of margin preferences to myOldColumnCount

		end if 
	on error 
		display dialog "The script failed for an unknown reason." 
	end try 
end tell
Technical Details
Message-ID: <1de7a699.-1@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,c9839df0c827155,start
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-02-01 03:37:39 PST
From: "Richard Ronnback" <richard.ronnback@telia.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Here's a script for exporting selected objects to PDF
Message-ID: <1de7a699.-1@WebX.la2eafNXanI>
Date: Sat, 1 Feb 2003 03:26:33 -0800
Lines: 83
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit