Search code examples
batch-filepdfvbscriptcmdbatch-processing

Print first page from each of 1000 PDF


By using .bat and .vbs. How it's possible to print first page from each of 1000 PDFs?

The only working solution, which I found is:

Option Explicit

Const FILE_TO_PRINT = "n:\xxx\xxx\xxx\xxx\xxxx.PDF"
Dim shl
Dim fldr
Dim files,file

Set shl = CreateObject("Shell.Application")
Set fldr = shl.Namespace("n:\HEAT06\BAA Cards\66712\20161103\")
Set files = fldr.Items


For Each file in files
  If LCase(file.Path) = LCase(FILE_TO_PRINT) Then
    file.InvokeVerbEx("Print")
  End If

Next

Set shl = Nothing
Set fldr = Nothing
Set files = Nothing
WScript.Quit

it's does work, BUT it will print whole document, when I need only first page.


Solution

  • Attached a VBS I wrote some years ago that will print the first page of all files you drop on it to the default printer. You may change it to that what you need. If you use it with drag & drop, keep in mind, that you have to drag the marked files from the first or last file in order to get the printouts sorted in the way you marked the files. HTH, Reinhard

     '//Print first page of pdfs
    
    set WshShell = CreateObject ("Wscript.Shell")
    set fs = CreateObject("Scripting.FileSystemObject")
    Set objArgs = WScript.Arguments
    
    if objArgs.Count < 1 then
        msgbox("Please drag a file on the script")
        WScript.quit
    end if
        'contact Acrobat
    Set gApp = CreateObject("AcroExch.App")
    gApp.show 'comment or take out to work in hidden mode
    
      'open via Avdoc and print
    for i=0 to objArgs.Count - 1
        FileIn = ObjArgs(i)
        Set AVDoc = CreateObject("AcroExch.AVDoc")
        If AVDoc.Open(FileIn, "") Then
            Set PDDoc = AVDoc.GetPDDoc()
            Set JSO = PDDoc.GetJSObject
            jso.print false, 0, 0, true
            gApp.CloseAllDocs
        end if
    next
    
    gApp.hide : gApp.exit : Quit()
    MsgBox "Done!"
    
    Sub Quit
      Set JSO = Nothing : Set PDDoc = Nothing : Set gApp =Nothing : Wscript.quit
    End Sub