00)InDesignをコントロールするの最近のブログ記事

41)PDFハイパーリンク作成

| コメント(0) | トラックバック(0)

こちらはハイパーリンク作成のサンプル。けっこう難しいです。最初にブックマークと同じくハイパーリンクオブジェクトを作成し、次にリンクテキストのリンク部分の領域を設定します。最後にリンクオブジェクトを作成し、その時、先ほど作成した2つの設定と下線の設定などを行って完成です。こんなところを読んでいるあなたはかなりのマニア。

tell application "Adobe InDesign CS2_J"
	tell document 1
		get properties of hyperlink 1
		--★ここから下でテキストをクリックしてページへのリンクを作成できる
		set theDest to make hyperlink page destination with properties ¬
		{destination page:page 3, view setting:fit window} 
		set myhyperlink to make hyperlink text source with properties ¬
			{source text:text from character 1 to character -2 of paragraph 2 of ¬
			text frame 1 of page 1}
		make hyperlink with properties {border color:black, highlight:invert, ¬
			border style:solid, hidden:false, destination:theDest, ¬
			source:myhyperlink, name:"456789", visible:false, width:thin}
	end tell
end tell

40)PDFのブックマーク作成

| コメント(0) | トラックバック(0)

ウィンドウ=>インタラクティブのブックマークパレットにブックマークを作成します。スクリプトを実行すると下図のような状態になり、PDFを作成するとこのブックマークは生きてきます。

as-indd.jpg

プログラムとしてはhyperlinkオブジェクトをまず作成し、そこにリンク先のページやそのページの開き方の設定をしておきます。出来上がったhyperlinkオブジェクトの情報は見えないのですが、2回目に同じ名前のものを作ろうとするとエラーが出てしまいます。
次にブックマークを作成。それのプロパティに先ほど作成したhyperlinkオブジェクトを入れておくと出来上がりです。
作ったブックマークの中にもう一つブックマークを作ると上図のように入れ子になったブックマークが出来上がります。

tell application "Adobe InDesign CS2_J"
	tell document 1
		--★ここから下でページへのリンクの親メニューを作成できる
		set theDest to make hyperlink page destination with properties ¬
			{destination page:page 5, view setting:fit window}
		set oyaBookMark to make bookmark with properties ¬
			{destination:theDest, name:"567"}
		--★ここから下でページへのリンクを作成できる
		set theDest to make hyperlink page destination with properties ¬
			{destination page:page 5, view setting:fit window}
		make bookmark at end of oyaBookMark with properties ¬
			{destination:theDest, name:"5"}
		--★ここから下でページへのリンクを作成できる
		set theDest to make hyperlink page destination with properties ¬
			{destination page:page 6, view setting:fit window}
		make bookmark at end of oyaBookMark with properties ¬
			{destination:theDest, name:"6"}
		--★ここから下でページへのリンクを作成できる
		set theDest to make hyperlink page destination with properties ¬
			{destination page:page 7, view setting:fit window}
		make bookmark at end of oyaBookMark with properties ¬
			{destination:theDest, name:"7"}
	end tell
end tell

表の中の選択部分の値段を取り出し入力した値をプラスします。値段の","のつけかたがベタです。。。

set ANS to display dialog "値段を入力してください。" default answer "1000"
set plusNum to text returned of ANS
set plusNum to my replaceAll(plusNum, "円", "")
set plusNum to my replaceAll(plusNum, ",", "")
set plusNum to plusNum as integer

set OriginalDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}

tell application "Adobe InDesign CS2_J"
	tell active document
		tell selection
			set cellCount to count cells
			repeat with N from 1 to cellCount
				set myData to contents of cell N
				set myData to my replaceAll(myData, "円", "")
				set myData to my replaceAll(myData, ",", "")
				set myData to myData as integer
				set myData to myData + plusNum
				set myData to myData as string
				if length of myData = 4 then
					set myData to (character 1 of myData & "," & ¬
						characters 2 thru 4 of myData & "円") as string
				else if length of myData = 5 then
					set myData to (characters 1 thru 2 of myData & "," & ¬
						characters 3 thru 5 of myData & "円") as string
				else if length of myData = 6 then
					set myData to (characters 1 thru 3 of myData & "," & ¬
						characters 4 thru 6 of myData & "円") as string
				end if
				set contents of cell N to myData
			end repeat
		end tell
	end tell
end tell
set AppleScript's text item delimiters to OriginalDelimiters

on replaceAll(motoStr, findStr, repStr)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {findStr}
	set motoStr to text items of motoStr
	set AppleScript's text item delimiters to {repStr}
	set motoStr to motoStr as string
	set AppleScript's text item delimiters to OriginalDelimiters
	return motoStr
end replaceAll

エントリー一覧

OpenID対応しています OpenIDについて
Powered by Movable Type 7.902.0
漢字イラストロジック-脳トレ京
FREE ONLINE SUDOKU