21.インデザインスクリプト 初級講座 PDF中綴じ面付け
管理者用前回は、がきの宛名をレイアウトを行いました。
インデザインを動かす部分は、今まで取り上げた内容で十分対応できると思います。
問題は、VBAの技術習得にかかっていると思います。
今回は、紹介するのは、PDFファイル操作ですが、初級講座12 で紹介した、PDFの取り込みを参考にしました。
VBAの習得を行う事により、様々な目的に活用できる形に変えて行く事が出来ると思います。
今回は、PDFファイルを中綴じ面付け用のファイルにする為のスクリプトを作ります。
中綴じ面付けに対しては、一般の方は、あまり馴染みが無いようにも思いますが、実際に使って見ると便利です。
ぜひ参考にしていただければと思います。
印刷屋さんでは、PDFファイルをインデザインに貼りつけて、PDFファイルで書き出しを行う、と言う事が出来ますと、様々な応用範囲が広がります。
もしかしたら、高額の専用ソフトと同じ様な事が可能となるかもしれません。
今回は、A4サイズの冊子をA5サイズに縮小して、中綴じ出力用に面付けします。
一般家庭では、中綴じ用のホッチキスはお持ちじゃないと思いますが、縮小印刷したものをプリントして折って束ねておくだけでも使い勝手の良い印刷物になります。活用して見てください。
又、スクリプト内の、用紙寸法、座標値を変えるだけで、他のサイズにも変更できます。色々研究して見てください。
スクリプトを実行します。
PDFファイルの選択
ファイル選択のダイアログ表示のステップを使用しました。
アドビの公式マニアルにあるものをそのまま持ってきました。
VBAからJavaScriptを起動して実行しているようです。
MsgBox "PDFファイル選択"
myInDesign.ScriptPreferences.UserInteractionLevel = idUserInteractionLevels.idInteractWithAll
myJavaScript = "myPDFFile = File.openDialog(""PDFファイルを選択して!!"");if(myPDFFile != null){myFileName = myPDFFile.fsName}else{myFileName = """"};"
myFileName = myInDesign.DoScript(myJavaScript, idScriptLanguage.idJavascript)
開始/終了ページの入力のスクリプトは、初級講座12と同じスクリプトを使用してます。
指定のページが、4の倍数でない場合は、白紙を入れて調整してます。
スクリプト全体
コピーをして使用してください。
あくまでもサンプルです。使用によって発生する不具合については、弊社の責任は無いことをご了解ください。
Option Explicit
Private Sub CommandButton1_Click()
Dim myInDesign, myDocument, myTextFrame, myTextFrame1
Dim dir_mei, INDD_name, myJavaScript, myFileName, myDialog
Dim myDialogColumn, myBorderPanelA, myTempDialogColumnA, myStaticTextA
Dim myPointSizeFieldA, myBorderPanelB, myTempDialogColumn, myStaticText
Dim myPointSizeField, stpege, edpege, naka_peg, bb, aa
Dim zen_pg, hakusi_puras, stno1, pdf_pag_st, pdf_pag_ed, peg_st, outpege
Dim haichi_1_YS, haichi_1_XS, haichi_1_YE, haichi_1_XE, myPDFset
Dim actpag
Rem 次の行は、インデザインを起動します。
Set myInDesign = CreateObject("InDesign.Application.CC_J") 'インデザインを起動する
dir_mei = "G:\NAVI_VBA"
INDD_name = dir_mei & "\テストサンプル.indd"
Set myDocument = myInDesign.Open(INDD_name)
With myDocument.DocumentPreferences
.PageHeight = "210mm"
.PageWidth = "297mm"
.FacingPages = False
'********************************************************************************************
Rem 裁ち落とし
.DocumentBleedBottomOffset = "3p"
.DocumentBleedTopOffset = "3p"
.DocumentBleedInsideOrLeftOffset = "3p"
.DocumentBleedOutsideOrRightOffset = "3p"
Rem 印刷可能領域
.SlugBottomOffset = "20mm"
.SlugTopOffset = "20mm"
.SlugInsideOrLeftOffset = "20mm"
.SlugRightOrOutsideOffset = "20mm"
End With
MsgBox "PDFファイル選択"
myInDesign.ScriptPreferences.UserInteractionLevel = idUserInteractionLevels.idInteractWithAll
myJavaScript = "myPDFFile = File.openDialog(""PDFファイルを選択して!!"");if(myPDFFile != null){myFileName = myPDFFile.fsName}else{myFileName = """"};"
myFileName = myInDesign.DoScript(myJavaScript, idScriptLanguage.idJavascript)
'MsgBox "ページ指定ダイアログ作成"
Set myDialog = myInDesign.Dialogs.Add
myDialog.CanCancel = True
myDialog.Name = "PDFデータ取込みページ入力" & myFileName '
Set myDialogColumn = myDialog.DialogColumns.Add
Rem 別のボーダーパネルを作成します。
Set myBorderPanelA = myDialogColumn.BorderPanels.Add
Rem ボーダーパネル内部のダイアログ列を作成します。
Set myTempDialogColumnA = myBorderPanelA.DialogColumns.Add
Set myStaticTextA = myTempDialogColumnA.StaticTexts.Add
myStaticTextA.StaticLabel = "PDF取込み開始ページ:"
Rem ボーダーパネル内部の別のダイアログ列を作成します。
Set myTempDialogColumnA = myBorderPanelA.DialogColumns.Add
Set myPointSizeFieldA = myTempDialogColumnA.RealEditboxes.Add
myPointSizeFieldA.EditValue = 1
Rem 終了ページのボーダーパネルを作成。
Set myBorderPanelB = myDialogColumn.BorderPanels.Add
Rem ボーダーパネル内部のダイアログ列を作成します。
Set myTempDialogColumn = myBorderPanelB.DialogColumns.Add
Set myStaticText = myTempDialogColumn.StaticTexts.Add
myStaticText.StaticLabel = "PDF取込み終了ページ:"
Rem ボーダーパネル内部の別のダイアログ列を作成します。
Set myTempDialogColumn = myBorderPanelB.DialogColumns.Add
Set myPointSizeField = myTempDialogColumn.RealEditboxes.Add
myPointSizeField.EditValue = 4
myDialog.Show
stpege = CInt(myPointSizeFieldA.EditValue)
edpege = CInt(myPointSizeField.EditValue)
'============================================================
naka_peg = edpege - stpege
bb = naka_peg \ 4
aa = naka_peg Mod 4
If Not aa = 0 Then
bb = bb + 1
End If
zen_pg = bb * 4
hakusi_puras = zen_pg / 2
stno1 = 0
If stpege = 1 Then
stno1 = 1
End If
pdf_pag_st = stpege
pdf_pag_ed = stpege + zen_pg - 1
peg_st = 0
For outpege = 1 To hakusi_puras Step 1
peg_st = peg_st + 1
If (peg_st Mod 2) = 0 Then
If pdf_pag_ed - edpege <= 0 Then
myInDesign.PDFPlacePreferences.PageNumber = pdf_pag_ed
Set myTextFrame = myDocument.Pages.Item(peg_st).TextFrames.Add
haichi_1_YS = 0
haichi_1_XS = 148
haichi_1_YE = 210
haichi_1_XE = 297
myTextFrame.GeometricBounds = Array(CStr(haichi_1_YS) + "mm", CStr(haichi_1_XS) + "mm", CStr(haichi_1_YE) + "mm", CStr(haichi_1_XE) + "mm")
Set myPDFset = myTextFrame.Place(myFileName)
myTextFrame.Fit idFitOptions.idContentToFrame '1668575078
End If
Else
myInDesign.PDFPlacePreferences.PageNumber = pdf_pag_st
Set myTextFrame = myDocument.Pages.Item(peg_st).TextFrames.Add
haichi_1_YS = 0
haichi_1_XS = 148
haichi_1_YE = 210
haichi_1_XE = 297
myTextFrame.GeometricBounds = Array(CStr(haichi_1_YS) + "mm", CStr(haichi_1_XS) + "mm", CStr(haichi_1_YE) + "mm", CStr(haichi_1_XE) + "mm")
Set myPDFset = myTextFrame.Place(myFileName)
myTextFrame.Fit idFitOptions.idContentToFrame '1668575078
End If
If (peg_st Mod 2) = 0 Then
myInDesign.PDFPlacePreferences.PageNumber = pdf_pag_st
Set myTextFrame1 = myDocument.Pages.Item(peg_st).TextFrames.Add
haichi_1_YS = 0
haichi_1_XS = 0
haichi_1_YE = 210
haichi_1_XE = 148
myTextFrame1.GeometricBounds = Array(CStr(haichi_1_YS) + "mm", CStr(haichi_1_XS) + "mm", CStr(haichi_1_YE) + "mm", CStr(haichi_1_XE) + "mm")
Set myPDFset = myTextFrame1.Place(myFileName)
myTextFrame1.Fit idFitOptions.idContentToFrame '1668575078
Else
If pdf_pag_ed - edpege <= 0 Then
myInDesign.PDFPlacePreferences.PageNumber = pdf_pag_ed
Set myTextFrame1 = myDocument.Pages.Item(peg_st).TextFrames.Add
haichi_1_YS = 0
haichi_1_XS = 0
haichi_1_YE = 210
haichi_1_XE = 148
myTextFrame1.GeometricBounds = Array(CStr(haichi_1_YS) + "mm", CStr(haichi_1_XS) + "mm", CStr(haichi_1_YE) + "mm", CStr(haichi_1_XE) + "mm")
Set myPDFset = myTextFrame1.Place(myFileName)
myTextFrame1.Fit idFitOptions.idContentToFrame '1668575078
End If
End If
pdf_pag_st = pdf_pag_st + 1
pdf_pag_ed = pdf_pag_ed - 1
Set myPDFset = myPDFset.Item(1)
actpag = myPDFset.PDFAttributes.PageNumber
If stno1 = 1 Then
stno1 = 0
Else
If actpag = 1 Then
Exit For
End If
End If
myDocument.Pages.Add
stpege = stpege + 1
Next
myDocument.Pages.Item(-1).Delete
myDialog.Destroy
End Sub