Read, merge, split PDF in Classic ASP

GemBox.Pdf is a .NET library that enable you to process PDF files from any .NET application. But it's also a COM accessible library that you can use in Classic ASP web page as well.

System Requirements

To use GemBox.Pdf in VBScript, you'll need to:

  1. Download and install GemBox.Pdf Setup.
  2. Expose GemBox.Pdf to COM Interop with Regasm.exe tool:
    :: Add GemBox.Pdf to COM registry for x86 (32-bit) applications.
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe [path to installed GemBox.Pdf.dll]
    :: Add GemBox.Pdf to COM registry for x64 (64-bit) applications.
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe [path to installed GemBox.Pdf.dll]

Working with PDF files in Classic ASP

The following example shows how you can read a PDF file from Classic ASP application, merge multiple PDF files into a single PDF and split a single PDF into multiple PDF files.

Merging PDF files into one and splitting PDF pages into multiple PDF files in Classic ASP
Screenshot of merged PDF files and split PDF pages
  ' Create ComHelper object.
  Set comHelper = Server.CreateObject("GemBox.Pdf.ComHelper")
  ' If using the Professional version, put your serial key below.

  Dim fileNames : fileNames = Array("\%#MergeFile01.pdf%", "\%#MergeFile02.pdf%", "\%#MergeFile03.pdf%")

  ''' Read PDF '''

  ' Load PDF file.
  Set document1 = comHelper.Load(Server.MapPath(".") & fileNames(0))
  Set pages1 = document1.Pages

  ' Read text content from each PDF page.
  For i1 = 0 To pages1.Count - 1
      Set page = pages1.Item(i1)
      Response.write(page.Content.ToString() & "<br>")


  ''' Merge PDF '''

  ' Create PdfDocument object.
  Set document2 = Server.CreateObject("GemBox.Pdf.PdfDocument")

  ' Merge multiple PDF files into a single PDF file.
  For i2 = 0 To UBound(fileNames)
      Set sourceDocument = comHelper.Load(Server.MapPath(".") & fileNames(i2))
      Set sourcePages = sourceDocument.Pages

      For j2 = 0 To sourcePages.Count - 1


  comHelper.Save document2, Server.MapPath(".") & "\Merge Files.pdf"

  ''' Split PDF '''

  ' Load PDF file.
  Set document3 = comHelper.Load(Server.MapPath(".") & "\Merge Files.pdf")
  Set pages3 = document3.Pages

  ' Split a single PDF file into multiple PDF files.
  For i3 = 0 To pages3.Count - 1
      Set destinationDocument = Server.CreateObject("GemBox.Pdf.PdfDocument")

      comHelper.Save destinationDocument, Server.MapPath(".") & "\Page" & i3 & ".pdf"


Wrapper Library

Not all members of GemBox.Pdf are accesible because of the COM limitations like unsupported static and overload methods. That is why you can use ComHelper class which provides alternatives for some members that cannot be called with COM Interop.

However, if you need to use many GemBox.Pdf members from VBScript, a recommended approach is to create a .NET wrapper library instead. Your wrapper library should do all the work within and exposes a minimal set of classes and methods to the unmanaged code.

This will enable you to take advantage of GemBox.Pdf's full capabilities, avoid any COM limitations, and improve performnace by reducing the number of COM Callable Wrappers created at runtime.

See also

Next steps

GemBox.Pdf is a .NET component that enables developers to read, merge and split PDF files or execute low-level object manipulations from .NET applications in a simple and efficient way.

Download Buy