从每 1000 个 PDF 打印第一页
Print first page from each of 1000 PDF
通过使用 .bat 和 .vbs。如何从 1000 个 PDF 中的每一个打印第一页?
我找到的唯一可行的解决方案是:
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 Cards712161103\")
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
它确实有效,但它会打印整个文档,而我只需要第一页。
附上我几年前写的一个 VBS,它将把你放在上面的所有文件的第一页打印到默认打印机。你可以把它改成你需要的。如果您将它与拖放一起使用,请记住,您必须从第一个或最后一个文件拖动标记的文件才能按照您标记文件的方式对打印输出进行排序。 HTH,莱因哈德
'//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
安装 Ghostscript 后,您可以使用以下代码(打开记事本,保存后将扩展名更改为 .bat)。您必须将 .bat 文件放在与您要打印的 PDF 相同的文件夹中。
代码是(gswin64c.exe 如果您有较新版本的 Ghostscript,可能会更改)
for %%I in (*.pdf) do "C:\Program Files\gs\gs9.55.0\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBATCH -sDEVICE#pdfwrite -sOutputFile#"%%~nI-page1.pdf" -dFirstPage#1 -dLastPage#1 "%%I"
你的问题很老了,但希望这会避免其他人像我一样花几个小时来解决它哈哈
通过使用 .bat 和 .vbs。如何从 1000 个 PDF 中的每一个打印第一页?
我找到的唯一可行的解决方案是:
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 Cards712161103\")
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
它确实有效,但它会打印整个文档,而我只需要第一页。
附上我几年前写的一个 VBS,它将把你放在上面的所有文件的第一页打印到默认打印机。你可以把它改成你需要的。如果您将它与拖放一起使用,请记住,您必须从第一个或最后一个文件拖动标记的文件才能按照您标记文件的方式对打印输出进行排序。 HTH,莱因哈德
'//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
安装 Ghostscript 后,您可以使用以下代码(打开记事本,保存后将扩展名更改为 .bat)。您必须将 .bat 文件放在与您要打印的 PDF 相同的文件夹中。
代码是(gswin64c.exe 如果您有较新版本的 Ghostscript,可能会更改)
for %%I in (*.pdf) do "C:\Program Files\gs\gs9.55.0\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBATCH -sDEVICE#pdfwrite -sOutputFile#"%%~nI-page1.pdf" -dFirstPage#1 -dLastPage#1 "%%I"
你的问题很老了,但希望这会避免其他人像我一样花几个小时来解决它哈哈