Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Thedark15
Femeie
19 ani
Bacau
cauta Barbat
24 - 46 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [PDF] Merge PDF with VBS Script and PDFTKBuilder Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 7 ani
Postari: 841
First download PDFTKBuilder from homepage (setup) or PortableApps.com as portable:

Place it in a folder you desire, I created a new folder in D drive and inside I placed the PDFTKBuilder folder together with the VBS script. You will see that in the beginning of the VBS script it detects the location of the script file, then identifies the pdftk.exe in the PDFTKBuilder folder which is under the same root folder as the VBS script.

The above ensures that the script is portable, this way it can run from a USB drive for example.

This script works by dragging and dropping at least 2 PDF files onto the VBS file.
- the order of the PDF files in the merged file is the natural order in the folder, but also the first PDF that is dropped.
- so, for example, if you want the 7th PDF in a folder to be the first in the merge, select all 7 PDFs, then drag them by the 7th PDF and drop them onto the VBS script.

The merged PDF file will be saved in the same folder as the other PDFs files.

Limitations:
- you must have all the PDF files you want to merge in the same location (it is the way drag & drop works anyway)

VBS script:

Set fso = CreateObject("Scripting.FileSystemObject")
scriptPath = fso.GetAbsolutePathName(WScript.ScriptFullName)
scriptFolder = fso.GetParentFolderName(scriptPath)
pdftkPath = scriptFolder & "\PDFTKBuilder\App\pdftkbuilder\pdftk.exe"

Set objArgs = WScript.Arguments
Set WshShell = CreateObject("WScript.Shell")

If objArgs.Count < 2 Then
    MsgBox "Please drag and drop at least 2 PDF files onto this script.", vbExclamation
    WScript.Quit
End If

pdfList = ""
For i = 0 To objArgs.Count - 1
    pdfFile = objArgs(i)
    If LCase(Right(pdfFile, 4)) = ".pdf" Then
        pdfList = pdfList & " """ & pdfFile & """"
    End If
Next

outputPathQuoted = """" & outputPath & """"
exePathQuoted = """" & pdftkPath & """"

If pdfList = "" Then
    MsgBox "No valid PDF files were provided.", vbExclamation
    WScript.Quit
End If

firstFile = objArgs(0)
folderPath = Left(firstFile, InStrRev(firstFile, "\") - 1)
timeNow = Right("0" & Hour(Time), 2) & "-" & _
          Right("0" & Minute(Time), 2) & "-" & _
          Right("0" & Second(Time), 2)
outputPath = folderPath & "\merged_" & timeNow & ".pdf"

outputPathQuoted = """" & outputPath & """"
exePathQuoted = """" & pdftkPath & """"

cmd = "cmd /c " & """" & exePathQuoted & pdfList & " cat output " & outputPathQuoted & """"
'i = inputbox("asdasda", , cmd)
WshShell.Run cmd, 0, True

MsgBox "PDF files merged: " & vbCrLf & outputPath, vbInformation


Source:
ChatGPT


pus acum 6 zile
   
Pagini: 1  

Mergi la