Information: Example
Merge multiple PDFs into one
 
Product Version Service Pack Code Samples  
Toolkit Std
Toolkit Pro
3.5.2
4.0
4.0 SR1
SP6
VBS
ASP
CF
PHP
 
Description
 
The following VBScript download provides an example of how to use the MergeFile method to combine multiple PDFs into one output PDF.

NOTE: This example is available in other codes. Choose from the Code Samples list above to display the download link for the example in the appropriate code for your environment.

These files are required:
  • Cover.PDF - The first input PDF.
  • Document.PDF - The second input PDF.
  • MergeFile.vbs - Code detail provided below.
Click here to download this example for VBScript (includes required files):
' Variables
    ' Template and Output files
    varOutputFile = "output.pdf"
    varMergeFile1 = "cover.pdf"
    varMergeFile2 = "document.pdf"
    
' Instantiate Object
Set TK = CreateObject("APToolkit.Object")

' OpenOutputFile
varReturn = TK.OpenOutputFile(varOutputFile)
If varReturn <> 0 Then Error("OpenOutputFile") End If

' Merge the files
varReturn = TK.MergeFile(varMergeFile1, 0, 0)
If varReturn <= 0 Then Error("MergeFile") End If

varReturn = TK.MergeFile(varMergeFile2, 0, 0)
If varReturn <= 0 Then Error("MergeFile") End If

' CloseOutputFile
TK.CloseOutputFile

' Clear Object
Set TK = Nothing

' Done
Msgbox "Success!"

' Error Handling
Sub Error(Method)
    Msgbox "'" & Method & "' failed with a '" & varReturn & _
            "'" & VBCRLF & "TK Return Codes:" & VBCRLF & _
            "http://www.activepdf.com/support/kb/?id=10670&tk=ts"
    Set TK = Nothing
    Wscript.Quit
End Sub
 
Keywords
 
duplicate, merge, combine, fit, together, create, generate, pdf, files, document, add, how, to, mergefile, merge, php, hypertext, preprocessor, toolkit, using, use, one, many, others, only, asp, cfm, cf, coldfusion, cold, fusion, VBS, VBScript, vb, script, example, create, from, html, text, method, property