フッターコンテンツにスキップ
移行ガイド

C#でCraftMyPDFからIronPDFに移行する方法

なぜCraftMyPDFからIronPDFに移行するのですか?

CraftMyPDFのようなクラウドベースのPDF APIは、多くの本番環境には適さない基本的な問題があります。

クラウドベースのPDF APIの問題点

1.データがシステムから送信されます:すべての HTML テンプレートと JSON データ ペイロードはCraftMyPDFのサーバーに送信されます。 請求書、契約書、医療記録、または機密性の高いビジネスデータについては、HIPAA、GDPR、SOC2 コンプライアンスのリスクが生じます。

2.ネットワーク遅延:CraftMyPDFのドキュメントには、PDF ごとに 1.5 ~ 30 秒と記載されています。 IronPdfはミリ秒単位でローカルに生成します。

  1. PDF ごとのコストが加算されます:サブスクリプション料金で 1 か月あたり 10,000 枚の PDF を使用すると、1 回限りの永久ライセンスと比べて、継続的に多額のコストが発生します。

4.印刷に最適化された出力:クラウド API は多くの場合、印刷用に最適化されています。つまり、背景を減らし、色を簡素化して"インク"を節約します。その結果、画面上の HTML とはまったく異なる外観になります。

5.テンプレートのロックイン:CraftMyPDFには、独自のドラッグ アンド ドロップ エディターが必要です。 標準的なHTML/CSSを自由に使用することはできません。

アーキテクチャの比較

アスペクト CraftMyPDF IronPDF
データロケーション クラウド オンプレミス(データが外に出ることはありません)
レイテンシーについて 1.PDF1枚あたり5~30秒 ミリ秒
価格について PDFごとの購読 1回限りの永久ライセンス
テンプレートシステム 独自のドラッグ&ドロップのみ あらゆるHTML/CSS/JavaScript
アウトプット品質 印刷に最適化 ピクセルパーフェクトな画面レンダリング
オフラインで動作します。 いいえ(インターネットが必要です) はい
コンプライアンス データリースの構成 SOC2/HIPAAフレンドリー

機能比較

フィーチャー CraftMyPDF IronPDF
HTMLからPDFへ APIテンプレート経由 ネイティブ
URLからPDFへ API経由 ネイティブ
カスタムテンプレート 専用エディタのみ あらゆるHTML
CSS3のサポート 制限的 フル
JavaScriptレンダリング 制限的 フル
PDFのマージ/分割 API経由 ネイティブ
透かし API経由 ネイティブ
オフラインでの作業
セルフホスト

移行前の準備

前提条件

あなたの環境がこれらの要件を満たしていることを確認してください:

  • .NET Framework 4.6.2+または.NET Core 3.1 / .NET 5-9
  • Visual Studio 2019+またはC#拡張機能付きVS Code
  • NuGetパッケージマネージャへのアクセス
  • IronPDFライセンスキー (ironpdf.com にて無料トライアル可能)

CraftMyPDFの使用状況を確認する

ソリューションディレクトリで以下のコマンドを実行し、すべてのCraftMyPDFの参照を確認してください:

# Find allCraftMyPDFusages in your codebase
grep -r "CraftMyPdf\|craftmypdf\|api.craftmypdf.com" --include="*.cs" .
grep -r "X-API-KEY" --include="*.cs" .

# Find API key references
grep -r "your-api-key\|template-id\|template_id" --include="*.cs" .

# Find NuGet package references
grep -r "CraftMyPdf\|RestSharp" --include="*.csproj" .
# Find allCraftMyPDFusages in your codebase
grep -r "CraftMyPdf\|craftmypdf\|api.craftmypdf.com" --include="*.cs" .
grep -r "X-API-KEY" --include="*.cs" .

# Find API key references
grep -r "your-api-key\|template-id\|template_id" --include="*.cs" .

# Find NuGet package references
grep -r "CraftMyPdf\|RestSharp" --include="*.csproj" .
SHELL

予想される画期的な変更

変更 CraftMyPDF IronPDF インパクト
アーキテクチャ クラウド REST API ローカル.NETライブラリ HTTPコールの削除
テンプレート 独自のエディタ 標準HTML テンプレートをHTMLに変換
APIキー すべての通話に必要 起動時のライセンス APIキーハンドリングの削除
非同期パターン 必須 (HTTP) オプション ご希望であれば、awaitを削除してください。
エラー処理 HTTPステータスコード 例外 try/catchパターンの変更
データバインディング JSONテンプレート 文字列の補間 データバインディングの簡素化

ステップごとの移行プロセス

ステップ 1: NuGet パッケージを更新する

HTTPクライアントライブラリを削除し、IronPDFをインストールしてください:

# Remove RestSharp HTTP client
dotnet remove package RestSharp

# Install IronPDF
dotnet add package IronPdf
# Remove RestSharp HTTP client
dotnet remove package RestSharp

# Install IronPDF
dotnet add package IronPdf
SHELL

ステップ 2: 名前空間参照の更新

HTTPクライアントの名前空間をIronPDFに置き換えてください:

// Remove these
using RestSharp;
using System.IO;

// Add this
using IronPdf;
// Remove these
using RestSharp;
using System.IO;

// Add this
using IronPdf;
Imports IronPdf
$vbLabelText   $csharpLabel

ステップ 3: ライセンスを設定する (起動時に 1 回)

リクエストごとのAPIキーヘッダを単一のライセンス構成に置き換える:

// Add at application startup (Program.cs or Global.asax)
// This replaces all X-API-KEY headers
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Global.asax)
// This replaces all X-API-KEY headers
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup (Program.vb or Global.asax)
' This replaces all X-API-KEY headers
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

完全な API 移行のリファレンス

APIエンドポイントのマッピング

CraftMyPDF IronPDF
POST /v1/create renderer.RenderHtmlAsPdf(html)
X-API-KEY ヘッダー License.LicenseKey = "..."
template_id 標準HTML文字列
{%name%} プレースホルダー $"{name}" C# 補間
POST /v1/merge PdfDocument.Merge(pdfs)
POST /v1/add-watermark pdf.ApplyWatermark(html)
Webhookコールバック 不要
料金制限 該当なし

コンフィギュレーション マッピング

CraftMyPDF オプション IronPDF 同等物
template_id HTML文字列
data JSON C#補間
page_size: "A4" PaperSize = PdfPaperSize.A4
orientation: "landscape" PaperOrientation = Landscape
margin_top: 20 MarginTop = 20
header HtmlHeader
footer HtmlFooter

コード移行の例

HTMLからPDFへの変換

最も一般的な操作は、クラウドAPIからローカルレンダリングへの基本的なアーキテクチャの移行を示しています。

CraftMyPDFの実装:

// NuGet: Install-Package RestSharp
using System;
using RestSharp;
using System.IO;

class Program
{
    static void Main()
    {
        var client = new RestClient("https://api.craftmypdf.com/v1/create");
        var request = new RestRequest(Method.POST);
        request.AddHeader("X-API-KEY", "your-api-key");
        request.AddJsonBody(new
        {
            template_id = "your-template-id",
            data = new
            {
                html = "<h1>Hello World</h1><p>This is a PDF from HTML</p>"
            }
        });

        var response = client.Execute(request);
        File.WriteAllBytes("output.pdf", response.RawBytes);
    }
}
// NuGet: Install-Package RestSharp
using System;
using RestSharp;
using System.IO;

class Program
{
    static void Main()
    {
        var client = new RestClient("https://api.craftmypdf.com/v1/create");
        var request = new RestRequest(Method.POST);
        request.AddHeader("X-API-KEY", "your-api-key");
        request.AddJsonBody(new
        {
            template_id = "your-template-id",
            data = new
            {
                html = "<h1>Hello World</h1><p>This is a PDF from HTML</p>"
            }
        });

        var response = client.Execute(request);
        File.WriteAllBytes("output.pdf", response.RawBytes);
    }
}
Imports System
Imports RestSharp
Imports System.IO

Module Program
    Sub Main()
        Dim client As New RestClient("https://api.craftmypdf.com/v1/create")
        Dim request As New RestRequest(Method.POST)
        request.AddHeader("X-API-KEY", "your-api-key")
        request.AddJsonBody(New With {
            .template_id = "your-template-id",
            .data = New With {
                .html = "<h1>Hello World</h1><p>This is a PDF from HTML</p>"
            }
        })

        Dim response = client.Execute(request)
        File.WriteAllBytes("output.pdf", response.RawBytes)
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDFの実装:

// NuGet: Install-Package IronPdf
using System;
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using System;
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
        pdf.SaveAs("output.pdf");
    }
}
Imports System
Imports IronPdf

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>")
        pdf.SaveAs("output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDFはRestClientのセットアップ、APIキーヘッダ、テンプレートID、HTTPレスポンスハンドリングを排除し、15行のクラウド操作を4行のローカルコードに削減します。 その他のオプションについては、HTML to PDF documentationを参照してください。

URLからPDFへの変換

CraftMyPDFの実装:

// NuGet: Install-Package RestSharp
using System;
using RestSharp;
using System.IO;

class Program
{
    static void Main()
    {
        var client = new RestClient("https://api.craftmypdf.com/v1/create");
        var request = new RestRequest(Method.POST);
        request.AddHeader("X-API-KEY", "your-api-key");
        request.AddJsonBody(new
        {
            template_id = "your-template-id",
            data = new
            {
                url = "https://example.com"
            },
            export_type = "pdf"
        });

        var response = client.Execute(request);
        File.WriteAllBytes("webpage.pdf", response.RawBytes);
    }
}
// NuGet: Install-Package RestSharp
using System;
using RestSharp;
using System.IO;

class Program
{
    static void Main()
    {
        var client = new RestClient("https://api.craftmypdf.com/v1/create");
        var request = new RestRequest(Method.POST);
        request.AddHeader("X-API-KEY", "your-api-key");
        request.AddJsonBody(new
        {
            template_id = "your-template-id",
            data = new
            {
                url = "https://example.com"
            },
            export_type = "pdf"
        });

        var response = client.Execute(request);
        File.WriteAllBytes("webpage.pdf", response.RawBytes);
    }
}
Imports System
Imports RestSharp
Imports System.IO

Module Program
    Sub Main()
        Dim client As New RestClient("https://api.craftmypdf.com/v1/create")
        Dim request As New RestRequest(Method.POST)
        request.AddHeader("X-API-KEY", "your-api-key")
        request.AddJsonBody(New With {
            .template_id = "your-template-id",
            .data = New With {
                .url = "https://example.com"
            },
            .export_type = "pdf"
        })

        Dim response = client.Execute(request)
        File.WriteAllBytes("webpage.pdf", response.RawBytes)
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDFの実装:

// NuGet: Install-Package IronPdf
using System;
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderUrlAsPdf("https://example.com");
        pdf.SaveAs("webpage.pdf");
    }
}
// NuGet: Install-Package IronPdf
using System;
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderUrlAsPdf("https://example.com");
        pdf.SaveAs("webpage.pdf");
    }
}
Imports System
Imports IronPdf

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
        pdf.SaveAs("webpage.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF の RenderUrlAsPdf メソッドは、JavaScript でレンダリングされたコンテンツを含む完全な Web ページをキャプチャします。 その他のオプションについては、URL to PDF documentationを参照してください。

ヘッダーとフッター

CraftMyPDFの実装:

// NuGet: Install-Package RestSharp
using System;
using RestSharp;
using System.IO;

class Program
{
    static void Main()
    {
        var client = new RestClient("https://api.craftmypdf.com/v1/create");
        var request = new RestRequest(Method.POST);
        request.AddHeader("X-API-KEY", "your-api-key");
        request.AddJsonBody(new
        {
            template_id = "your-template-id",
            data = new
            {
                html = "<h1>Document Content</h1>",
                header = "<div>Page Header</div>",
                footer = "<div>Page {page} of {total_pages}</div>"
            }
        });

        var response = client.Execute(request);
        File.WriteAllBytes("document.pdf", response.RawBytes);
    }
}
// NuGet: Install-Package RestSharp
using System;
using RestSharp;
using System.IO;

class Program
{
    static void Main()
    {
        var client = new RestClient("https://api.craftmypdf.com/v1/create");
        var request = new RestRequest(Method.POST);
        request.AddHeader("X-API-KEY", "your-api-key");
        request.AddJsonBody(new
        {
            template_id = "your-template-id",
            data = new
            {
                html = "<h1>Document Content</h1>",
                header = "<div>Page Header</div>",
                footer = "<div>Page {page} of {total_pages}</div>"
            }
        });

        var response = client.Execute(request);
        File.WriteAllBytes("document.pdf", response.RawBytes);
    }
}
Imports System
Imports RestSharp
Imports System.IO

Module Program
    Sub Main()
        Dim client As New RestClient("https://api.craftmypdf.com/v1/create")
        Dim request As New RestRequest(Method.POST)
        request.AddHeader("X-API-KEY", "your-api-key")
        request.AddJsonBody(New With {
            .template_id = "your-template-id",
            .data = New With {
                .html = "<h1>Document Content</h1>",
                .header = "<div>Page Header</div>",
                .footer = "<div>Page {page} of {total_pages}</div>"
            }
        })

        Dim response = client.Execute(request)
        File.WriteAllBytes("document.pdf", response.RawBytes)
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDFの実装:

// NuGet: Install-Package IronPdf
using System;
using IronPdf;
using IronPdf.Rendering;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
        {
            CenterText = "Page Header"
        };
        renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
        {
            CenterText = "Page {page} of {total-pages}"
        };

        var pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>");
        pdf.SaveAs("document.pdf");
    }
}
// NuGet: Install-Package IronPdf
using System;
using IronPdf;
using IronPdf.Rendering;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
        {
            CenterText = "Page Header"
        };
        renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
        {
            CenterText = "Page {page} of {total-pages}"
        };

        var pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>");
        pdf.SaveAs("document.pdf");
    }
}
Imports System
Imports IronPdf
Imports IronPdf.Rendering

Module Program
    Sub Main()
        Dim renderer = New ChromePdfRenderer()
        renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
            .CenterText = "Page Header"
        }
        renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
            .CenterText = "Page {page} of {total-pages}"
        }

        Dim pdf = renderer.RenderHtmlAsPdf("<h1>Document Content</h1>")
        pdf.SaveAs("document.pdf")
    End Sub
End Module
$vbLabelText   $csharpLabel

IronPDF は、動的なページ番号付けのために、{page}{total-pages} などのプレースホルダー トークンをサポートしています。 その他のオプションについては、headers and footers documentationを参照してください。

テンプレート変数の変換

CraftMyPDFは独自のテンプレートプレースホルダーを使用しているため、C#の文字列補間に変換する必要があります:

CraftMyPDFパターン:

//CraftMyPDFtemplate variables
request.AddJsonBody(new
{
    template_id = "invoice-template",
    data = new
    {
        customer = "John Doe",
        amount = "$1,000",
        items = invoiceItems
    }
});
//CraftMyPDFtemplate variables
request.AddJsonBody(new
{
    template_id = "invoice-template",
    data = new
    {
        customer = "John Doe",
        amount = "$1,000",
        items = invoiceItems
    }
});
'CraftMyPDFtemplate variables
request.AddJsonBody(New With {
    .template_id = "invoice-template",
    .data = New With {
        .customer = "John Doe",
        .amount = "$1,000",
        .items = invoiceItems
    }
})
$vbLabelText   $csharpLabel

IronPDFパターン:

// C# string interpolation
var html = $@"
<html>
<body>
    <h1>Invoice</h1>
    <p>Customer: {customerName}</p>
    <p>Amount: {amount}</p>
    {GenerateItemsTable(invoiceItems)}
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(html);
// C# string interpolation
var html = $@"
<html>
<body>
    <h1>Invoice</h1>
    <p>Customer: {customerName}</p>
    <p>Amount: {amount}</p>
    {GenerateItemsTable(invoiceItems)}
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(html);
Dim html As String = $"
<html>
<body>
    <h1>Invoice</h1>
    <p>Customer: {customerName}</p>
    <p>Amount: {amount}</p>
    {GenerateItemsTable(invoiceItems)}
</body>
</html>"

Dim pdf = renderer.RenderHtmlAsPdf(html)
$vbLabelText   $csharpLabel

重要な移行に関する注意事項

すべての HTTP コードを削除します

最も大きな変更点は、ネットワーク依存の排除です。 IronPDFはローカルで動作し、RestClientもAPIコールもレスポンス処理も行いません:

//CraftMyPDF- HTTP required
var client = new RestClient("https://api.craftmypdf.com/v1/create");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-KEY", "your-api-key");
var response = await client.ExecuteAsync(request);

//IronPDF- no HTTP
var pdf = renderer.RenderHtmlAsPdf(html);
//CraftMyPDF- HTTP required
var client = new RestClient("https://api.craftmypdf.com/v1/create");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-KEY", "your-api-key");
var response = await client.ExecuteAsync(request);

//IronPDF- no HTTP
var pdf = renderer.RenderHtmlAsPdf(html);
Imports RestSharp

'CraftMyPDF- HTTP required
Dim client As New RestClient("https://api.craftmypdf.com/v1/create")
Dim request As New RestRequest(Method.POST)
request.AddHeader("X-API-KEY", "your-api-key")
Dim response = Await client.ExecuteAsync(request)

'IronPDF- no HTTP
Dim pdf = renderer.RenderHtmlAsPdf(html)
$vbLabelText   $csharpLabel

レート制限コードの削除

CraftMyPDFは、再試行ロジックを必要とするAPIレート制限を課しています。 IronPDFに限界はありません:

//CraftMyPDF- needed to avoid 429 errors
await Task.Delay(100);
if (response.StatusCode == TooManyRequests) { /* retry */ }

//IronPDF- no limits, just generate
var pdf = renderer.RenderHtmlAsPdf(html);
// Remove all rate limit code!
//CraftMyPDF- needed to avoid 429 errors
await Task.Delay(100);
if (response.StatusCode == TooManyRequests) { /* retry */ }

//IronPDF- no limits, just generate
var pdf = renderer.RenderHtmlAsPdf(html);
// Remove all rate limit code!
$vbLabelText   $csharpLabel

Webhookハンドラの削除

CraftMyPDFはPDFの補完に非同期ウェブフックを使用しています。 IronPdfは同期的であり、PDFはすぐに準備できます:

//CraftMyPDF- webhook callback required
// POST with webhook_url, wait for callback

//IronPDF- PDF ready immediately
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
// No callback needed!
//CraftMyPDF- webhook callback required
// POST with webhook_url, wait for callback

//IronPDF- PDF ready immediately
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
// No callback needed!
'CraftMyPDF- webhook callback required
' POST with webhook_url, wait for callback

'IronPDF- PDF ready immediately
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
' No callback needed!
$vbLabelText   $csharpLabel

デフォルトで同期

async/awaitパターンがHTTP呼び出しにのみ必要な場合は、削除してください:

//CraftMyPDF- async required
var response = await client.ExecuteAsync(request);

//IronPDF- sync by default (async available if needed)
var pdf = renderer.RenderHtmlAsPdf(html);
//CraftMyPDF- async required
var response = await client.ExecuteAsync(request);

//IronPDF- sync by default (async available if needed)
var pdf = renderer.RenderHtmlAsPdf(html);
$vbLabelText   $csharpLabel

移行後のチェックリスト

コードの移行が完了したら、以下を確認してください:

  • すべてのPDF生成テストを実行する
  • 出力品質を比較する(IronPDFのChromiumエンジンはピクセルパーフェクトにレンダリングします)
  • パフォーマンスの改善を測定(ミリ秒対秒)
  • すべてのテンプレートが正しく変換されていることを確認する
  • レート制限なしでバッチ処理をテストする
  • すべてのターゲット環境でテストする
  • CI/CDパイプラインを更新する
  • CraftMyPDFのサブスクリプションをキャンセルする
  • secrets/config から API キーを削除する

PDFインフラストラクチャの将来性を確保する

.NET 10が目前に迫り、C# 14が新しい言語機能を導入する中、ローカルPDFライブラリを選択することで、クラウドAPIの廃止リスクやバージョン互換性の懸念を排除することができます。 IronPDFの永久ライセンスモデルは、プロジェクトが2025年や2026年まで延長されても、定期的なサブスクリプションコストやデータがインフラから離れることなく、移行への投資が無期限に配当されることを意味します。

その他のリソース


CraftMyPDFからIronPDFに移行することで、クラウド依存性、ネットワーク遅延、PDFごとのコスト、テンプレートのロックインを排除し、オフラインで動作するピクセルパーフェクトなChromiumレンダリングを実現します。REST API呼び出しからローカルメソッド呼び出しへの移行により、コードベースが簡素化され、機密性の高いドキュメントデータをインフラ内に保持できます。

カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

アイアンサポートチーム

私たちは週5日、24時間オンラインで対応しています。
チャット
メール
電話してね