' Copyright (c) 2021 ActivePDF, Inc. ' ActivePDF Toolkit 2018 ' Example generated 03/08/21 Dim FSO, strPath, intOpenOutputFile, intOpenInputFile, _ intAddPageRange, intCopyForm ' Get current path Set FSO = CreateObject("Scripting.FileSystemObject") strPath = FSO.GetFile(Wscript.ScriptFullName).ParentFolder & "\" Set FSO = Nothing ' Instantiate Object Set oTK = CreateObject("APToolkit.Object") ' Create the new PDF file intOpenOutputFile = oTK.OpenOutputFile(strPath & "new.pdf") If intOpenOutputFile <> 0 Then ErrorHandler "OpenOutputFile", intOpenOutputFile End If ' Open the template PDF intOpenInputFile = oTK.OpenInputFile(strPath & "10pages.pdf") If intOpenInputFile <> 0 Then ErrorHandler "OpenInputFile", intOpenInputFile End If ' Using page ranges first, before using CopyFrom will improve performance ' Once CopyFrom or MergeFile are called then the actual copy of the specified ' page ranges will occur ' Add a page rage and stamp it with the original page number oTK.SetFont "Helvetica", 12, 1 oTK.PrintText 72, 760, "Originally page 1", 1 intAddPageRange = oTK.AddPageRange(1, 1) If intAddPageRange <> 1 Then ErrorHandler "AddPageRange", intAddPageRange End If oTK.SetFont "Helvetica", 12, 3 oTK.PrintText 72, 760, "Originally page 3", 3 intAddPageRange = oTK.AddPageRange(3, 3) If intAddPageRange <> 1 Then ErrorHandler "AddPageRange", intAddPageRange End If oTK.SetFont "Helvetica", 12, 5 oTK.PrintText 72, 760, "Originally page 5", 5 intAddPageRange = oTK.AddPageRange(5, 5) If intAddPageRange <> 1 Then ErrorHandler "AddPageRange", intAddPageRange End If ' Copy the set page ranges to the new file ' CopyForm parameters will be ignored when using AddPageRange intCopyForm = oTK.CopyForm(0, 0) If intCopyForm <> 1 Then ErrorHandler "CopyForm", intCopyForm End If ' Close the new file to complete PDF creation oTK.CloseOutputFile ' Release Object Set oTK = Nothing ' Process Complete Wscript.Echo("Done!") ' Error Handling Sub ErrorHandler(method, outputCode) Wscript.Echo("Error in " & method & ": " & outputCode) End Sub