VBScript

Acrobatを使ってPDFファイルを結合するVBScript

Acrobat PDF 結合 コマンドライン」といったキーワード検索でのアクセスがありました。
AcrobatによるPDFファイルの結合処理をコマンドラインから実行したい方による検索だと思います。

Adobeフォーラムの下記スレッドを見る限り、残念ながらAcrobatにはそういった機能は用意されていないようです(Distillerの方は未確認です)。

> Is there a way to combine pdf files from the command line on Windows by passing arguments in to an executable? I have Acrobat XI Pro.

Not out of the box, no, Acrobat doesn’t support that functionality. You could, however, write a command line program that would call on Acrobat to do the work, however. You could also write a program inside of Acrobat to do this, either as a plugin or via JavaScript.

Combine PDF files programmatically(https://forums.adobe.com/thread/1524493) より

そこで、数年前に書いた下記マクロを手直しして、ドラッグ&ドロップした複数のPDFファイルを結合するVBScriptを書いてみました。

'**********************************************
' Acrobatを使ってPDFファイルを結合するVBScript
' @kinuasa
'**********************************************
Option Explicit

Dim args
Dim fso
Dim pdoc
Dim n, ts, fp
Dim cnt, i
Const PDSaveFull = 1
Const OutputFileName = "merged_" '結合後のファイル名

Set args = WScript.Arguments
If args.Count < 1 Then
  MsgBox "当スクリプトにPDFファイルをドラッグ&ドロップして処理を実行してください。", vbExclamation + vbSystemModal
  WScript.Quit
End If

cnt = 0
Set fso = CreateObject("Scripting.FileSystemObject")
For i = 0 To args.Count - 1
  Select Case LCase(fso.GetExtensionName(args(i)))
    Case "pdf": cnt = cnt + 1
  End Select
Next
If cnt < 2 Then
  MsgBox "2個以上のPDFファイルを選択してください。", vbExclamation + vbSystemModal
  WScript.Quit
End If

'出力先設定
n = Now()
ts = Year(n) & Right("0" & Month(n), 2) & _
     Right("0" & Day(n), 2) & Right("0" & Hour(n), 2) & _
     Right("0" & Minute(n), 2) & Right("0" & Second(n), 2)
fp = fso.BuildPath(fso.GetFile(args(0)).ParentFolder.Path, OutputFileName & ts & ".pdf")

With CreateObject("AcroExch.PDDoc")
  If .Create = True Then
    Set pdoc = CreateObject("AcroExch.PDDoc")
    For i = 0 To args.Count - 1
      Select Case LCase(fso.GetExtensionName(args(i)))
        Case "pdf"
          If pdoc.Open(args(i)) = True Then
            .InsertPages .GetNumPages() - 1, pdoc, 0, pdoc.GetNumPages() - 1, True
            pdoc.Close
          End If
      End Select
    Next
    Set pdoc = Nothing
    .Save PDSaveFull, fp
    .Close
  End If
End With

MsgBox "結合したPDFファイルを【" & fp & "】に保存しました。", vbInformation + vbSystemModal

上記スクリプトを実行すると、元のファイルと同じフォルダに結合されたPDFファイルが出力されます。

コードのメッセージ表示部分を修正すれば、コマンドラインからバッチ処理として実行することもできるので、大量のPDFファイルの結合処理にお悩みの方は是非一度お試しください。

[Google Apps Script]メールからMessage-IDヘッダーを取得する前のページ

「みんなで情シス!第2回」に参加します。次のページ

関連記事

  1. Windows 10

    Microsoft Edgeを起動するVBScript

    前回の記事の関連ですが、下記コードのようにShellExecuteメソ…

  2. VBScript

    Illustratorに登録されたPDFプリセットを列挙するVBScript

    前回の記事で、VBSからIllustratorが操作できることを紹介し…

  3. VBScript

    ファイル選択ダイアログ

    ファイル選択ダイアログを表示するVBScriptをまとめてみま…

  4. Office関連

    PDFファイルに差し込み印刷するVBAマクロ

    このページにもあるように、AcrobatはOLEオートメーション機能に…

  5. Excel

    フォルダ内にあるExcelファイルをカウントするVBScript

    「フォルダ内 Excel 数える VBScript」といったキーワード…

  6. Office関連

    PDFを他のファイル形式に変換するVBAマクロ

    「PDF 変換 Word VBA」といったキーワード検索でのアクセスが…

コメント

  • コメント (0)

  • トラックバックは利用できません。

  1. この記事へのコメントはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP