Skip to main content
Interwork Corporation
IDR Solutions Product Support Portal
モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動

C#を使用してBuildVuマイクロサービスにアクセスする

目次

  1. はじめに
  2. 前提条件
  3. コード例
  4. コールバックURLに結果を返す
  5. 設定オプション
  6. URLでのアップロード
  7. 認証の使用
  8. 詳細情報

はじめに

このチュートリアルでは、ホストされたBuildVuクラウドAPIを使用してPDFファイルをHTMLまたはSVGに変換する方法を説明します。使用可能なサービスには以下が含まれます:

これらのサービスは通常のHTTPリクエストでアクセスできますが、このチュートリアルではオープンソースのC# IDRCloudClient を使用します。これはREST API のシンプルなC#ラッパーを提供します。

前提条件

nugetを使用して、以下のコマンドでidrsolutions-csharp-clientパッケージ をインストールしてください:

nuget install idrsolutions-csharp-client

コード例

以下は、PDFファイルをHTMLまたはSVGに変換するための基本的なコード例です。設定オプションと高度な機能については、以下をご覧ください。

using System;
using System.Collections.Generic;
using idrsolutions_csharp_client;

class ExampleUsage
{
    static void Main(string[] args)
    {
        
        var client = new IDRCloudClient("https://cloud.idrsolutions.com/cloud/" + IDRCloudClient.BUILDVU);

        try
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>
            { 
                //["token"] = "Token", //Required only when connecting to the IDRsolutions trial and cloud subscription service
                ["input"] = IDRCloudClient.UPLOAD,
                ["file"] = "path/to/input.pdf"
            };

            Dictionary<string, string> results = client.Convert(parameters);

            String outputUrl = results.GetValueOrDefault("downloadUrl", "No download URL provided");
            
            client.DownloadResult(results, "path/to/output/dir");

            Console.WriteLine("Converted: " + outputUrl);
        }
        catch (Exception e)
        {
            Console.WriteLine("Conversion failed: " + e.Message);
        }
    }
}

コールバックURLに結果を返す

BuildVuマイクロサービスは、変換完了時に変換のステータス を送信するコールバックURLを受け付けます。コールバックURLを使用することで、変換が完了したかどうかを判断するためにサービスをポーリングする必要がなくなります。
コールバックURLは以下のようにconvertメソッドに提供できます。

Dictionary<string, string> parameters = new Dictionary<string, string>
{ 
    //["token"] = "Token", //Required only when connecting to the IDRsolutions trial and cloud subscription service
    ["callbackUrl"] = "http://listener.url",
    ["input"] = IDRCloudClient.UPLOAD,
    ["file"] = "path/to/input.pdf"
};

設定オプション

BuildVu APIは、変換をカスタマイズするためのキーと値のペアの設定オプションを含む文字列化されたJSONオブジェクトを受け付けます。設定はparameters配列に追加する必要があります。PDFファイルをHTMLまたはSVGに変換するための設定オプションの完全なリストはこちら で確認できます。

["settings"] = "{\"key\":\"value\",\"key\":\"value\"}"

URLでのアップロード

ローカルファイルをアップロードする以外に、BuildVuマイクロサービスがダウンロードして変換を実行するURLを提供することもできます。これを行うには、parameters変数のinputとfileの値を以下のように置き換える必要があります。

["input"] = IDRCloudClient.DOWNLOAD
["url"] = "http://exampleURL/exampleFile.pdf"

認証の使用

PDFファイルをHTMLまたはSVGに変換するためにユーザー名とパスワードが必要な独自のBuildVuマイクロサービスをデプロイした場合、各変換でそれらを提供する必要があります。これらは以下のように、usernameとpasswordという名前の2つの変数をconvertメソッドに渡すことで提供されます。

var client = new IDRCloudClient("http://exampleURL.com/" + IDRCloudClient.BUILDVU, "username", "password");

詳細情報

GitHubのIDRCloudClient
NugetのIDRCloudClient
BuildVuマイクロサービスAPI
BuildVuマイクロサービスの使用