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. VBScript

    Internet Explorerのお気に入りを列挙するVBScript

    Internet Explorerのお気に入りにどの位のインターネット…

  2. Windows関連

    右クリックメニューからフォルダを管理者権限で開く(コマンド プロンプト)

    フォルダをShiftキーを押しながら右クリックすると、「コマンド ウィ…

  3. Excel

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

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

  4. VBScript

    OWSPostDataオブジェクトを使って文字列をエンコードするVBS

    OWSPostDataオブジェクトのURLEncodeメソッドで文字列…

  5. Excel

    Officeファイルから作成者などのプロパティを取得するVBScript

    下記記事でも書いていますが、xlsxやdocxといった、OOXML形式…

  6. VBScript

    [クライアント管理]WMI Explorerの紹介

    端末のハードウェア情報やインストールされているソフトウェアなどを調べる…

コメント

  • コメント (0)

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP