BCL easyPDF SDK
easyPDF SDK Usermanual
PDF Creator Programming API  |  Download Free Trial  |  Contact Us to Purchase

ASP Sample

IMPORTANT!
If you use the Printer object, then make sure to
configure the easyPDF SDK Loader object

This example shows how to convert Microsoft Word document into PDF using ASP script with IIS version 5.

Note: To learn about basics of using the easyPDF SDK objects in different programming languages, please refer to the Using easyPDF Objects section.

ASP Setup:

  1. Prepare a Word document and an ASP script. Copy the files into the IIS Scripts working folder (e.g., "C:\Inetpub\Scripts").
  2. Write a test script. Shown below is an example script.

    Note: To access easyPDF SDK enumeration types from ASP (not needed for ASP.NET), create the Global.asa file in the root folder (e.g., "C:\Inetpub\wwwroot"), and declare the type library as following:
            
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF Printer SDK 8 Type Library"
    UUID="{D04DA9DF-250D-42E3-B5BF-EFB2FFF0D886}"
    VERSION="8.0"
    -->
    
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF PDF Processor SDK 8 Type Library"
    UUID="{5DFD8A56-BCA8-4529-9A4C-25E0F743B886}"
    VERSION="8.0"
    -->
    
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF PDF Converter SDK 8 Type Library"
    UUID="{33E0AF63-1637-451E-9EA7-B0501D39847F}"
    VERSION="8.0"
    -->
    
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF PDF Document SDK 8 Type Library"
    UUID="{BCF5F49F-5321-40BE-B02A-11A58AE10D46}"
    VERSION="8.0"
    -->
    
    ASP Example 1 (VBScript):
    <%@ Language=VBScript %>
    <%
    Option Explicit
    
    Dim oLoader
    Dim oPrinter
    Dim oPrintJob
    
    ' For ASP, instead of getting the Printer object directly,
    ' get it through the easyPDF SDK Loader object.
    Set oLoader = Server.CreateObject("easyPDF.Loader.8")
    
    Set oPrinter = oLoader.LoadObject("easyPDF.Printer.8")
    Set oPrintJob = oPrinter.PrintJob
    
    On Error Resume Next
    
    ' Convert to PDF.
    Call oPrintJob.PrintOut(Server.MapPath("./input.doc"), Server.MapPath("./output.pdf"))
    
    If Err Then
        Response.Write("<B>Failed!</B> " + Err.Description + "<BR>")
        Response.Write("Conversion Result: " + oPrintJob.ConversionResultMessage + "<BR>")
        Response.Write("Printer Result: " + oPrintJob.PrinterResultMessage + "<BR>")
        Response.End
    End If
    
    Response.Write("<B>Success!</B><BR>")
    %>
    
    ASP Example 2 (VBScript):
    <%@ Language=VBScript %>
    <%
    Option Explicit
    
    Dim oLoader
    Dim oPrinter
    Dim oPrintJob
    Dim arrPDF
    
    ' For ASP, instead of getting the Printer object directly,
    ' get it through the easyPDF SDK Loader object.
    Set oLoader = Server.CreateObject("easyPDF.Loader.8")
    
    Set oPrinter = oLoader.LoadObject("easyPDF.Printer.8")
    Set oPrintJob = oPrinter.PrintJob
    
    On Error Resume Next
    
    ' Get output PDF in memory (VT_ARRAY | VT_UI1).
    arrPDF = oPrintJob.PrintOut2(Server.MapPath("./input.doc"))
    
    If Err Then
        Response.Write("<B>Failed!</B> " + Err.Description + "<BR>")
        Response.Write("Conversion Result: " + oPrintJob.ConversionResultMessage + "<BR>")
        Response.Write("Printer Result: " + oPrintJob.PrinterResultMessage + "<BR>")
        Response.End
    End If
    
    On Error Goto 0
    
    ' Push the PDF file into browser.
    Response.Clear
    Response.ContentType = "application/pdf"
    Response.AddHeader "Content-Disposition", "inline; filename=output.pdf"
    Response.Buffer = True
    Response.BinaryWrite arrPDF
    Response.End
    %>
    
    ASP.NET Example (C# code snippet):
    // You need to add easyPDF SDK COM objects into your application.
    // From your project, go to "Project" -> "Add Reference..." menu
    // to bring up the Add Reference dialog, click the COM tab, and
    // then select all easyPDF SDK objects you will be using.
    
    using BCL.easyPDF.Interop.easyPDFLoader;
    using BCL.easyPDF.Interop.easyPDFPrinter;
    
    // ...
    
    Loader oLoader = null;
    Printer oPrinter = null;
    PrintJob oPrintJob = null;
    
    try
    {
        // Instead of getting the Printer object directly,
        // get it through the easyPDF SDK Loader object.
        oLoader = new Loader();
    
        oPrinter = (Printer)oLoader.LoadObject("easyPDF.Printer.8");
        oPrintJob = oPrinter.PrintJob;
    
        // Convert to PDF.
        oPrintJob.PrintOut(Server.MapPath("./input.doc"), Server.MapPath("./output.pdf"));
    
        Response.Write("<B>Success!</B>");
    }
    catch(System.Runtime.InteropServices.COMException err)
    {
        // Error handling code.
    
        Response.Write("<B>Failed!</B> " + err.Message + "<BR>");
    
        if(err.ErrorCode == (int)prnResult.PRN_R_CONVERSION_FAILED
        && oPrintJob != null)
        {
            Response.Write("Conversion Result: " + oPrintJob.ConversionResultMessage);
    
            prnConversionResult result = oPrintJob.ConversionResult;
    
            if(result == prnConversionResult.PRN_CR_CONVERSION
            || result == prnConversionResult.PRN_CR_CONVERSION_INIT
            || result == prnConversionResult.PRN_CR_CONVERSION_PRINT)
            {
                Response.Write("Printer Result: " + oPrintJob.PrinterResultMessage);
            }
        }
    }
    
  3. Make sure to have input.doc in the current IIS working folder (e.g., "C:\Inetpub\Scripts").
  4. Run it in web browser (e.g., http://localhost/scripts/pdftest.asp).