Read, merge, split PDF in Classic ASP
GemBox.Pdf is a .NET library that enables you to process PDF files from any .NET application. But it's also a COM-accessible library that you can use in the Classic ASP web page as well. To use GemBox.Pdf in VBScript, you'll need to: 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. Not all members of GemBox.Pdf are accessible because of the COM limitations like unsupported static and overload methods. That is why you can use 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 expose 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 performance by reducing the number of COM Callable Wrappers created at runtime.System Requirements
:: 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
<%
' Create ComHelper object.
Set comHelper = Server.CreateObject("GemBox.Pdf.ComHelper")
' If using the Professional version, put your serial key below.
comHelper.SetLicense("FREE-LIMITED-KEY")
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>")
Next
document1.Dispose()
'''''''''''''''''
''' 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
document2.Pages.AddClone(sourcePages.Item(j2))
Next
sourceDocument.Dispose()
Next
comHelper.Save document2, Server.MapPath(".") & "\Merge Files.pdf"
document2.Dispose()
'''''''''''''''''
''' 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")
destinationDocument.Pages.AddClone(pages3.Item(i3))
comHelper.Save destinationDocument, Server.MapPath(".") & "\Page" & i3 & ".pdf"
destinationDocument.Dispose()
Next
document3.Dispose()
%>
Wrapper Library
ComHelper
class which provides alternatives for some members that cannot be called with COM Interop.