ASPサンプル

 

重要!

プリンタオブジェクトを使用する場合、
easyPDF SDK Loaderオブジェクトの設定をしていることを確認してください。

 

 

ここではMicrosoft WordドキュメントをIIS バージョン5のASPスクリプトを使用してPDFへ変換する方法を紹介します。

Note: 異なるプログラミング言語を用いてのeasyPDF SDKオブジェクトの使い方の基本については、easyPDFオブジェクトの使用セクションを参照してください。


ASPセットアップ:

  1. WordドキュメントとASPスクリプトを準備します。ファイルをIISスクリプトワーキングフォルダにコピーします。(例 "C:\Inetpub\Scripts")



  2. テスト スクリプトを書きます。下記の例を参照。

    Note: ASP(ASP.NETでは必要なし) からeasyPDF SDKエニュメレーションタイプへアクセスする場合、 ルートフォルダ内(例"C:\Inetpub\wwwroot") にGlobal.asaファイルを作成し、下記のようにタイプライブラリを宣言してください。
            
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF Printer SDK 5 Type Library"
    UUID="{9CE5FC56-E2A6-4361-86B7-BF0FD4BCD295}"
    VERSION="5.0"
    -->
    
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF PDF Processor SDK 5 Type Library"
    UUID="{60AE69C7-B0FA-453D-B524-E7DF5431D7AC}"
    VERSION="5.0"
    -->
    
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF PDF Converter SDK 5 Type Library"
    UUID="{33B3E88D-E894-4048-A939-D215AE33311F}"
    VERSION="5.0"
    -->
    
    <!--
    METADATA TYPE="TypeLib"
    NAME="BCL easyPDF PDF Document SDK 5 Type Library"
    UUID="{08CC91EB-D7AE-4315-B393-AC02899F68D2}"
    VERSION="5.0"
    -->
    
    ASP 例 1 (VBScript):
    <%@ Language=VBScript %>
    <%
    Option Explicit
    
    Dim oLoader
    Dim oPrinter
    Dim oPrintJob
    
    ' ASP用にプリンタオブジェクトを直接得る代わりに 
    ' easyPDF SDK Loaderオブジェクトを介してプリンタオブジェクトをgetします。
    Set oLoader = Server.CreateObject("easyPDF.Loader.5")
    
    Set oPrinter = oLoader.LoadObject("easyPDF.Printer.5")
    Set oPrintJob = oPrinter.PrintJob
    
    On Error Resume Next
    
    ' PDFへ変換します。
    Call oPrintJob.PrintOut(Server.MapPath("./input.doc"), Server.MapPath("./output.doc.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 例 2 (VBScript):
    <%@ Language=VBScript %>
    <%
    Option Explicit
    
    Dim oLoader
    Dim oPrinter
    Dim oPrintJob
    Dim arrPDF
    
    ' ASP用にプリンタオブジェクトを直接得る代わりに
    ' easyPDF SDK Loaderオブジェクトを介してプリンタオブジェクトをgetします。
    Set oLoader = Server.CreateObject("easyPDF.Loader.5")
    
    Set oPrinter = oLoader.LoadObject("easyPDF.Printer.5")
    Set oPrintJob = oPrinter.PrintJob
    
    On Error Resume Next
    
    ' メモリ (VT_ARRAY | VT_UI1)内のアウトプットPDFをGetします。
    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
    
    ' PDFファイルをブラウザへPushします。
    Response.Clear
    Response.ContentType = "application/pdf"
    Response.AddHeader "Content-Disposition", "inline; filename=output.pdf"
    Response.Buffer = True
    Response.BinaryWrite arrPDF
    Response.End
    %>
    
    ASP.NET 例 (C# code snippet):
    // easyPDF SDK COMオブジェクトをお使いのアプリケーションに付加する必要があります。
    // オブジェクトから"Project" -> "Add Reference..." メニューへ行き、
    // Add Referenceダイアログを立ち上げます。COMタブをクリックし、 
    // 使用している全てのeasyPDF SDKオブジェクトを選択します。
    
    using BCL.easyPDF.Interop.EasyPDFLoader;
    using BCL.easyPDF.Interop.EasyPDFPrinter;
    
    // ...
    
    Loader oLoader = null;
    Printer oPrinter = null;
    PrintJob oPrintJob = null;
    
    try
    {
        // ASP用にプリンタオブジェクトを直接得る代わりに 
        // easyPDF SDK Loaderオブジェクトを介してプリンタオブジェクトをgetします。
        Type type = Type.GetTypeFromProgID("easyPDF.Loader.5");
        oLoader = (Loader)Activator.CreateInstance(type);
    
        oPrinter = (Printer)oLoader.LoadObject("easyPDF.Printer.5");
        oPrintJob = oPrinter.PrintJob;
    
        // PDFへ変換します。
        oPrintJob.PrintOut(Server.MapPath("./input.doc"), Server.MapPath("./output.doc.pdf"));
    
        Response.Write("<B>Success!</B>");
    }
    catch(System.Runtime.InteropServices.COMException err)
    {
        // エラーハンドリングコード
    
        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. Input.docがIIS ワーキングフォルダ内(例"C:\Inetpub\Scripts")にあることを確認してください。
  4. ウェブ ブラウザ上で実行します。(例 http://localhost/scripts/pdftest.asp).