Da ja mehrere Leute eine Lösung gesucht haben um 2 unterschiedliche Wasserzeichen auf ein PDF zu bringen, wollte ich hier mal meine Lösung einbringen.
Jetzt mit Abfrage ob überhaupt mehrere Seiten vorhanden sind.
Es gibt sicher bessere Möglichkeiten das zu lösen. Hier bin ich für Input dankbar.
' AddWatermarkToPDF script
' Part of PDFCreator
' License: GPL
' Homepage: http://www.sf.net/projects/pdfcreator
' Version: 1.1.0.0
' Date: September, 1. 2005
' Author: Frank Heindörfer
' Comments: This script needs pdftk.
' For more informations about the freeware pdftk use this link:
' http://www.accesspdf.com
Option Explicit
Const AppTitle = "PDFCreator - AddWatermarkToPDF"
Const PathToPdftk = "d:\\PDFCreator\\pdftk.exe"
Const WatermarkPDF = "Briefbogen_KFB.pdf"
Const WatermarkPDF1 = "KFB-Seite2.pdf"
Dim objArgs, fname, tfname, tfname1, tfname2, tfname3, tfname4, tfname5, fso, WshShell, oExec
Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then
MsgBox "This script needs a parameter!", vbExclamation, AppTitle
WScript.Quit
End If
fname = objArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
If Ucase(fso.GetExtensionName(fname)) <> "PDF" Then
MsgBox "This script works only with pdf files!", vbExclamation, AppTitle
WScript.Quit
End If
If Not fso.FileExists(PathToPdftk) Then
MsgBox "You need pdftk for this script!" & vbcrlf & vbcrlf & _
"Please go to http://www.accesspdf.com and download it.", vbExclamation, AppTitle
WScript.Quit
End If
If Not fso.FileExists(WatermarkPDF) Then
MsgBox "Can't find the watermark pdf file!", vbExclamation, AppTitle
WScript.Quit
End If
Set WshShell = CreateObject("WScript.Shell")
tfname = fso.GetTempName
tfname1 = fso.GetTempName
tfname2 = fso.GetTempName
tfname3 = fso.GetTempName
tfname4 = fso.GetTempName
tfname5 = fso.GetTempName
WshShell.Run PathToPdftk & " A=""" & fname & """ cat A2-end output """ & tfname5 & """ ",0,true
If fso.FileExists(tfname5) Then
WshShell.Run PathToPdftk & " A=""" & fname & """ cat A1 output """ & tfname1 & """ ",0,true
WshShell.Run PathToPdftk & " """ & tfname1 & """ stamp " & WatermarkPDF & " output """ & tfname2 & """ ",0,true
WshShell.Run PathToPdftk & " A=""" & fname & """ cat A2-end output """ & tfname3 & """ ",0,true
WshShell.Run PathToPdftk & " """ & tfname3 & """ stamp " & WatermarkPDF1 & " output """ & tfname4 & """ ",0,true
WshShell.Run PathToPdftk & " """ & tfname2 & """ """ & tfname4 & """ cat output """ & tfname & """ ",0,true
else
WshShell.Run PathToPdftk & " A=""" & fname & """ cat A1 output """ & tfname1 & """ ",0,true
WshShell.Run PathToPdftk & " """ & tfname1 & """ stamp " & WatermarkPDF & " output """ & tfname & """ ",0,true
End If
If Not fso.FileExists(tfname) Then
MsgBox "There was an error using ""pdftk""!", vbCritical, AppTitle
WScript.Quit
End If
If fso.FileExists(fname) Then
fso.DeleteFile(fname)
End If
If fso.FileExists(tfname1) Then
fso.DeleteFile(tfname1)
End If
If fso.FileExists(tfname2) Then
fso.DeleteFile(tfname2)
End If
If fso.FileExists(tfname3) Then
fso.DeleteFile(tfname3)
End If
If fso.FileExists(tfname4) Then
fso.DeleteFile(tfname4)
End If
If fso.FileExists(tfname5) Then
fso.DeleteFile(tfname5)
End If
fso.MoveFile tfname, fname