フッターコンテンツにスキップ
ビデオ

C# PDF レンダリングを遅延させるための WaitFor の使用方法

PDFium .NET ラッパーからの移行により、IronPDFを利用することで、ネイティブバイナリ依存を持つレンダリング中心のエンジンから、プラットフォーム固有の複雑さにとらわれず、作成、操作、レンダリングを網羅する包括的なPDFソリューションに.NET PDFワークフローを移行できます。 このガイドは、ネイティブ依存関係の管理を排除し、PDFium自体が提供しない機能を追加するステップバイステップの移行パスを提供します。

PDFiumラッパーからIronPDFへ移行する理由

PDFium .NET ラッパーの理解

PDFiumは、GoogleのBSD-3-Clause C++ PDFレンダリングおよび解析エンジンで、Chromeの組み込みPDFビューアを支えるエンジンです。 公式のGoogle提供 for .NETバインディングはありません。 代わりに、.NET エコシステムはコミュニティのラッパーを介してPDFiumを利用しています。 最も一般的に引用される4つのNuGetパッケージは、PdfiumViewer(pvginkel; Apache 2.0; 2019年8月にアーカイブされ、2017年11月に最後のリリース2.13.0、.NET Framework 2.0+)、PdfiumViewer.Updated(.NET Core / .NET 6に移植されたメンテフォーク)、PDFiumCore(Dtronix; .NET Standard 2.1 P/Invokeバインディング)、およびPdfium.Net.SDK(Patagames; 商用、永続ライセンスSDK)

それらのAPIは異なりますが、共通点があります。それは、PDFium自体がレンダリングと解析のエンジンであり、HTMLからPDFへの変換エンジンまたは文書作成エンジンではないことです。PDFiumにはHTMLパーサーが備わっていないため、どのラッパーも単独ではHTMLをPDFに変換することができません。 このガイドは、APIが最も広く引用されているため、"before"スニペット用の代表ラッパーとしてPdfiumViewerを使用します; 移行のアプローチは、いずれの4つの場合も同じです。

重要なPDFiumラッパーの制限事項

  1. レンダリングファースト:PDFiumにはHTMLパーサーがないため、どのラッパーもHTML、URL、または任意の画像からPDFを作成することはできません。

  2. オープンソースラッパーでの限定的な操作:PdfiumViewer / PDFiumCore は、閲覧および1ページごとのテキスト抽出を提供します; マージ/分割/フォーム編集はPatagames Pdfium.Net.SDKでは一部サポートされており、無料のラッパーではほとんどサポートされていません。

  3. ネイティブバイナリ依存関係: 各RIDごとにプラットフォーム固有のPDFiumバイナリ(pdfium.dll / .so / .dylib)が必要です。

  4. デプロイの複雑さ: 各プラットフォームに合わせて、x86、x64、およびランタイムフォルダを含むネイティブバイナリをバンドルして管理する必要があります。

  5. 基本的なテキスト抽出: PdfiumViewerはGetPdfText(int)を介してページごとの生テキストを公開します; レイアウト/フォーマットメタデータは公開されていません。

  6. HTMLからPDFへ変換できません: PDFiumにはHTMLパーサーがありません; ウェブコンテンツを直接変換することはできません。

  7. 組み込みのヘッダー/フッターはありません: 高レベルのページオーバーレイAPIはありません。

  8. 組み込みの透かしなし: 原始的なスタンピングはありません。

  9. フォーム: 無料ラッパーでは読み取り専用または存在しません。 Patagames Pdfium.Net.SDKで利用可能です。

  10. セキュリティ: 無料のラッパーでは公開されていない暗号化/権限; Patagames Pdfium.Net.SDKで利用可能です。

PDFiumラッパーとIronPDFの比較

アスペクト PDFium .NET ラッパー IronPDF
主な焦点 レンダリング/ビューイング 完全なPDFソリューション
レンダリング忠実度 忠実度の高いレンダリング 特にHTML/CSS/JSについては、高いレベルが求められます。
HTMLからのPDF作成 None はい(HTML、URL、画像)
PDF操作 無料のラッパー:なし; Patagames: 部分的 はい(結合、分割、編集)
HTMLからPDFへ None はい(Chromiumエンジン)
ウォーターマーク ビルトインではない はい
ヘッダー/フッター ビルトインではない はい
フォーム入力 無料のラッパー:なし; Patagames: yes はい
セキュリティ 無料のラッパー:なし; Patagames: yes はい
ネイティブの依存関係 必須 バンドル / NuGet管理
クロスプラットフォーム 手動ネイティブバイナリ管理 自動翻訳
展開のしやすさ ネイティブの依存関係が複雑 より簡単に; 依存関係の複雑さを軽減

現代 for .NETを目指すチームにとって、IronPDFは、ネイティブバイナリの管理を排除し、包括的なPDF作成および操作機能を追加する完全管理型の基盤を提供します。


始める前に

前提条件

  1. .NET環境: .NET Framework 4.6.2+ または.NET Core 3.1+ / .NET 5/6/7/8/9+
  2. NuGetアクセス: NuGetパッケージをインストールする機能
  3. IronPDFライセンス: IronPDFからライセンスキーを取得します。

NuGetパッケージの変更

# Remove whichever PDFium wrapper you used:
#  PdfiumViewer           (Apache 2.0 - archived 2019, .NET Framework only)
#   PdfiumViewer.Updated    (community fork, .NET Core / .NET 6)
#   PDFiumCore              (Dtronix - .NET Standard 2.1 P/Invoke bindings)
#   Pdfium.Net.SDK          (Patagames - commercial, perpetual license)
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Updated
dotnet remove package PDFiumCore
dotnet remove package Pdfium.Net.SDK

# Install IronPDF
dotnet add package IronPdf
# Remove whichever PDFium wrapper you used:
#  PdfiumViewer           (Apache 2.0 - archived 2019, .NET Framework only)
#   PdfiumViewer.Updated    (community fork, .NET Core / .NET 6)
#   PDFiumCore              (Dtronix - .NET Standard 2.1 P/Invoke bindings)
#   Pdfium.Net.SDK          (Patagames - commercial, perpetual license)
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Updated
dotnet remove package PDFiumCore
dotnet remove package Pdfium.Net.SDK

# Install IronPDF
dotnet add package IronPdf
SHELL

ライセンス構成

// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

PDFiumラッパーの使用を特定する

# Find PDFium wrapper usage
grep -rE "PdfiumViewer|PDFiumCore|Patagames\.Pdf|PdfDocument\.Load|\.Render\(" --include="*.cs" .

# Find native binary references
grep -rE "pdfium\.dll|libpdfium\.(so|dylib)" --include="*.csproj" --include="*.config" .

# Find platform-specific code
grep -rE "#if.*64|WIN32|WIN64|LINUX|OSX" --include="*.cs" .
# Find PDFium wrapper usage
grep -rE "PdfiumViewer|PDFiumCore|Patagames\.Pdf|PdfDocument\.Load|\.Render\(" --include="*.cs" .

# Find native binary references
grep -rE "pdfium\.dll|libpdfium\.(so|dylib)" --include="*.csproj" --include="*.config" .

# Find platform-specific code
grep -rE "#if.*64|WIN32|WIN64|LINUX|OSX" --include="*.cs" .
SHELL

完全な API リファレンス

名前空間の変更

// PDFium wrappers (use the one you installed)
using PdfiumViewer;             //PdfiumViewer/PdfiumViewer.Updated
using PDFiumCore;               // Dtronix PDFiumCore (P/Invoke bindings)
using Patagames.Pdf;            // Patagames Pdfium.Net.SDK
using Patagames.Pdf.Net;        // Patagames Pdfium.Net.SDK

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// PDFium wrappers (use the one you installed)
using PdfiumViewer;             //PdfiumViewer/PdfiumViewer.Updated
using PDFiumCore;               // Dtronix PDFiumCore (P/Invoke bindings)
using Patagames.Pdf;            // Patagames Pdfium.Net.SDK
using Patagames.Pdf.Net;        // Patagames Pdfium.Net.SDK

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
Imports PdfiumViewer 'PdfiumViewer/PdfiumViewer.Updated
Imports PDFiumCore ' Dtronix PDFiumCore (P/Invoke bindings)
Imports Patagames.Pdf ' Patagames Pdfium.Net.SDK
Imports Patagames.Pdf.Net ' Patagames Pdfium.Net.SDK

Imports IronPdf
Imports IronPdf.Rendering
Imports IronPdf.Editing
$vbLabelText   $csharpLabel

コア クラス マッピング

PdfiumViewer IronPDF ノート
PdfiumViewer.PdfDocument IronPdf.PdfDocument 異なる名前空間で同じシンプルな名前
PdfRenderer(WinFormsコントロール) (該当なし) PdfiumViewerもUIコントロールを提供します; IronPDFはヘッドレスです
(利用できません) ChromePdfRenderer HTML / URL → PDF
(利用できません) HtmlHeaderFooter ヘッダー/フッター

ドキュメント読み込みマッピング

PdfiumViewer IronPDF ノート
PdfDocument.Load(path) PdfDocument.FromFile(path) ファイルから読み込む
PdfDocument.Load(stream) PdfDocument.FromStream(stream) ストリームから読み込む
(byteをMemoryStreamでラップする) PdfDocument.FromBinaryData(bytes) バイトから読み込む

ドキュメント プロパティのマッピング

PdfiumViewer IronPDF ノート
document.PageCount document.PageCount 同じ
IList<SizeF> document.Pages[index].Width / Height PdfiumViewerはサイズを公開します。 pages are not first-class objects
document.PageSizes[i].Width document.Pages[i].Width ページごとの幅(ポイント単位)

テキスト抽出マッピング

PdfiumViewer IronPDF ノート
document.GetPdfText(pageIndex) document.Pages[index].Text ページあたり
(マニュアルループ) document.ExtractAllText() すべてのページ

ドキュメント マッピングの保存

PdfiumViewer IronPDF ノート
document.Save(stream) document.SaveAs(path) PdfiumViewer は Stream を受け取ります。IronPDFはパスを取得します
(利用できません) document.Stream 生のストリームにアクセス
(利用できません) document.BinaryData バイト

ページ レンダリング マッピング

PdfiumViewer IronPDF ノート
document.Render(page, width, height, dpiX, dpiY, flags) pdf.RasterizeToImageFiles(path, DPI) ラスタライズ
document.Render(i, ...) への手動ループ pdf.RasterizeToImageFiles("page_*.png") 全ページにわたってバッチレンダーを実行します
手動スケール数学 DPI = 72 * scale DPIへのスケール変換

PDFiumラッパーにはない新機能

IronPDFの特徴 翻訳内容
ChromePdfRenderer.RenderHtmlAsPdf() HTMLから作成
ChromePdfRenderer.RenderUrlAsPdf() URLから作成
ChromePdfRenderer.RenderHtmlFileAsPdf() HTMLファイルから作成
PdfDocument.Merge() PDFの結合
pdf.CopyPages() ページの抜粋
pdf.RemovePages() ページの削除
pdf.InsertPdf() 位置にPDFを挿入
pdf.ApplyWatermark() 透かしの追加
pdf.AddHtmlHeaders() ヘッダーの追加
pdf.AddHtmlFooters() フッターの追加
pdf.SecuritySettings パスワード保護
pdf.SignWithDigitalSignature() デジタル署名
pdf.Form フォーム入力

コード移行の例

例1: PDFからのテキスト抽出

翻訳前 (PdfiumViewer):

// NuGet: Install-PackagePdfiumViewer (Apache 2.0; archived Aug 2019, .NET Framework 2.0+)
//        or Install-Package PdfiumViewer.Updated  (maintained fork, .NET Core / .NET 6)
//        or Install-Package PDFiumCore             (Dtronix, .NET Standard 2.1 P/Invoke)
//        or Install-Package Pdfium.Net.SDK         (Patagames, commercial perpetual license)
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // PdfiumViewer's text extraction is per-page raw text via GetPdfText(int).
                // No layout / format metadata is exposed.
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
// NuGet: Install-PackagePdfiumViewer (Apache 2.0; archived Aug 2019, .NET Framework 2.0+)
//        or Install-Package PdfiumViewer.Updated  (maintained fork, .NET Core / .NET 6)
//        or Install-Package PDFiumCore             (Dtronix, .NET Standard 2.1 P/Invoke)
//        or Install-Package Pdfium.Net.SDK         (Patagames, commercial perpetual license)
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // PdfiumViewer's text extraction is per-page raw text via GetPdfText(int).
                // No layout / format metadata is exposed.
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Text

Module Program
    Sub Main()
        Dim pdfPath As String = "document.pdf"

        Using document = PdfDocument.Load(pdfPath)
            Dim text As New StringBuilder()

            For i As Integer = 0 To document.PageCount - 1
                ' PdfiumViewer's text extraction is per-page raw text via GetPdfText(int).
                ' No layout / format metadata is exposed.
                Dim pageText As String = document.GetPdfText(i)
                text.AppendLine(pageText)
            Next

            Console.WriteLine(text.ToString())
        End Using
    End Sub
End Module
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        string pdfPath = "document.pdf";

        var pdf = PdfDocument.FromFile(pdfPath);
        string text = pdf.ExtractAllText();

        Console.WriteLine(text);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        string pdfPath = "document.pdf";

        var pdf = PdfDocument.FromFile(pdfPath);
        string text = pdf.ExtractAllText();

        Console.WriteLine(text);
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

        Dim pdfPath As String = "document.pdf"

        Dim pdf = PdfDocument.FromFile(pdfPath)
        Dim text As String = pdf.ExtractAllText()

        Console.WriteLine(text)
    End Sub
End Class
$vbLabelText   $csharpLabel

ここでの違いは重要です。 PdfiumViewerは各ページをusingステートメントを適切に管理して適切に廃棄する必要があります。また、返されたテキストはレイアウト/フォーマットメタデータなしのページごとの生テキストです。

IronPDFでは、数行でこれを簡略化します:ExtractAllText()で抽出し、出力します。 ExtractAllText() メソッドはすべてのページを自動的に処理します。 ページごとの抽出が必要な場合は、pdf.Pages[index].Textを使用できます。 追加オプションについては、テキスト抽出のドキュメントを参照してください。

例 2: PDF のマージ

翻訳前 (PdfiumViewer):

// NuGet: Install-PackagePdfiumViewer (representative open-source PDFium wrapper)
//PdfiumViewerand PDFiumCore do not expose PDF merge APIs - PDFium itself
// is a rendering / parsing engine, not a document-authoring engine.
// (Patagames Pdfium.Net.SDK exposes some document-edit operations but is commercial.)
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // To merge PDFs from a PDFium wrapper you must reach for another library
        // (PdfSharp, iText, IronPDF) or, with Patagames Pdfium.Net.SDK, use its
        // document-edit APIs.

        Console.WriteLine("PDF merging is not supported byPdfiumViewer/PDFiumCore.");
    }
}
// NuGet: Install-PackagePdfiumViewer (representative open-source PDFium wrapper)
//PdfiumViewerand PDFiumCore do not expose PDF merge APIs - PDFium itself
// is a rendering / parsing engine, not a document-authoring engine.
// (Patagames Pdfium.Net.SDK exposes some document-edit operations but is commercial.)
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // To merge PDFs from a PDFium wrapper you must reach for another library
        // (PdfSharp, iText, IronPDF) or, with Patagames Pdfium.Net.SDK, use its
        // document-edit APIs.

        Console.WriteLine("PDF merging is not supported byPdfiumViewer/PDFiumCore.");
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Collections.Generic

Module Program
    Sub Main()
        Dim pdfFiles As New List(Of String) From {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        }

        ' To merge PDFs from a PDFium wrapper you must reach for another library
        ' (PdfSharp, iText, IronPDF) or, with Patagames Pdfium.Net.SDK, use its
        ' document-edit APIs.

        Console.WriteLine("PDF merging is not supported by PdfiumViewer/PDFiumCore.")
    End Sub
End Module
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // PdfDocument.Merge accepts an IEnumerable<PdfDocument>, so load each file first.
        var docs = pdfFiles.Select(path => PdfDocument.FromFile(path)).ToList();
        var merged = PdfDocument.Merge(docs);
        merged.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // PdfDocument.Merge accepts an IEnumerable<PdfDocument>, so load each file first.
        var docs = pdfFiles.Select(path => PdfDocument.FromFile(path)).ToList();
        var merged = PdfDocument.Merge(docs);
        merged.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic
Imports System.Linq

Module Program
    Sub Main()
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

        Dim pdfFiles As New List(Of String) From {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        }

        ' PdfDocument.Merge accepts an IEnumerable(Of PdfDocument), so load each file first.
        Dim docs = pdfFiles.Select(Function(path) PdfDocument.FromFile(path)).ToList()
        Dim merged = PdfDocument.Merge(docs)
        merged.SaveAs("merged.pdf")

        Console.WriteLine("PDFs merged successfully")
    End Sub
End Module
$vbLabelText   $csharpLabel

この例は能力のギャップを明らかにしています。無料のPDFiumラッパー(PdfiumViewer、PDFiumCore)はマージAPIを公開していません。Patagames Pdfium.Net.SDKはいくつかのドキュメント編集操作を公開していますが、商業製品です。

IronPDFは、PdfDocument.FromFile()で読み込んでから、結果のドキュメントを結合します。 結果はSaveAs()で保存します。 PDFのマージと分割については、こちらをご覧ください。

例3: HTMLからPDFへの変換

翻訳前 (PdfiumViewer):

// NuGet: Install-PackagePdfiumViewer (representative PDFium wrapper)
// PDFium is a PDF rendering / parsing engine. It has NO HTML parser, so no
// PDFium .NET wrapper (PdfiumViewer, PdfiumViewer.Updated, PDFiumCore,
// Pdfium.Net.SDK) can convert HTML to PDF on its own.
using PdfiumViewer;
using System;
using System.IO;
using System.Drawing.Printing;

class Program
{
    static void Main()
    {
        // PDFium has no native HTML-to-PDF capability.
        // Produce the PDF with another engine (wkhtmltopdf, headless Chromium,
        // IronPDF, etc.) and then load it with PdfDocument.Load(...) for rendering.
        string htmlContent = "<h1>Hello World</h1>";

        Console.WriteLine("HTML to PDF conversion is not supported by PDFium.");
    }
}
// NuGet: Install-PackagePdfiumViewer (representative PDFium wrapper)
// PDFium is a PDF rendering / parsing engine. It has NO HTML parser, so no
// PDFium .NET wrapper (PdfiumViewer, PdfiumViewer.Updated, PDFiumCore,
// Pdfium.Net.SDK) can convert HTML to PDF on its own.
using PdfiumViewer;
using System;
using System.IO;
using System.Drawing.Printing;

class Program
{
    static void Main()
    {
        // PDFium has no native HTML-to-PDF capability.
        // Produce the PDF with another engine (wkhtmltopdf, headless Chromium,
        // IronPDF, etc.) and then load it with PdfDocument.Load(...) for rendering.
        string htmlContent = "<h1>Hello World</h1>";

        Console.WriteLine("HTML to PDF conversion is not supported by PDFium.");
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Drawing.Printing

Module Program
    Sub Main()
        ' PDFium has no native HTML-to-PDF capability.
        ' Produce the PDF with another engine (wkhtmltopdf, headless Chromium,
        ' IronPDF, etc.) and then load it with PdfDocument.Load(...) for rendering.
        Dim htmlContent As String = "<h1>Hello World</h1>"

        Console.WriteLine("HTML to PDF conversion is not supported by PDFium.")
    End Sub
End Module
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
Imports IronPdf
Imports System

Module Program
    Sub Main()
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

        Dim renderer As New ChromePdfRenderer()
        Dim htmlContent As String = "<h1>Hello World</h1>"

        Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
        pdf.SaveAs("output.pdf")

        Console.WriteLine("PDF created successfully")
    End Sub
End Module
$vbLabelText   $csharpLabel

この例は、最も大きな能力の違いを示しています。 PDFiumにはHTMLパーサーがないため、そのままでは.NETラッパーはHTMLをPDFに変換できません。

IronPDFは、ChromePdfRendererを通じたネイティブHTMLからPDFへの変換を提供しており、内部的にChromiumエンジンを使用してHTML、CSS、JavaScriptを正確にレンダリングします。 RenderHtmlAsPdf() メソッドはHTML文字列を直接PDFドキュメントに変換します。 IronPDFは、RenderHtmlFileAsPdf()でHTMLファイルをレンダリングすることもできます。 包括的な例については、HTML to PDF documentationを参照してください。


ネイティブ依存性の除去

PDFiumラッパーからIronPDFへの移行の最も重要な利点の一つは、ネイティブバイナリ管理を排除することです。

以前(PDFiumラッパー)- 複雑なデプロイメント

MyApp/
├── ビン/
│ ├──MyApp.dll
│   ├── PdfiumViewer.dll      # or PDFiumCore.dll / Patagames.Pdf.dll
│ ├── x86/
│ └── pdfium.dll
│ └── x64/
└─ pdfium.dll
ランタイム
│ ├── win-x86/native/
│ └── pdfium.dll
│   ├── win-x64/native/
│ └── pdfium.dll
│   ├── linux-x64/native/
│   │   └── libpdfium.so
│   └── osx-x64/native/
│       └── libpdfium.dylib

翻訳後 (IronPDF) - クリーンなデプロイメント

MyApp/
├── ビン/
│ ├──MyApp.dll
│ └─ IronPDF.dll # 含まれるものすべて

ネイティブ バイナリ参照の削除

# Delete native PDFium binaries
rm -rf x86/x64/runtimes/

# Remove from .csproj
# Delete any <Content Include="pdfium.dll" /> entries
# Delete any <None Include="x86/pdfium.dll" /> entries
# Delete native PDFium binaries
rm -rf x86/x64/runtimes/

# Remove from .csproj
# Delete any <Content Include="pdfium.dll" /> entries
# Delete any <None Include="x86/pdfium.dll" /> entries
SHELL

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

スケールからDPIへの変換

PdfiumViewerの Render(...) はdpiX/dpiYを明示的に取り、PDFiumの基礎となるレンダリングはスケール駆動型(1.0 = 72 DPI)です。 IronPDFはDPIを直接使用します。

// Formula:IronPDFDPI = 72 × PDFium scale
// PDFium scale 2.0 →IronPDFDPI 144
pdf.RasterizeToImageFiles("*.png", DPI: 144);
// Formula:IronPDFDPI = 72 × PDFium scale
// PDFium scale 2.0 →IronPDFDPI 144
pdf.RasterizeToImageFiles("*.png", DPI: 144);
' Formula: IronPDFDPI = 72 × PDFium scale
' PDFium scale 2.0 → IronPDFDPI 144
pdf.RasterizeToImageFiles("*.png", DPI:=144)
$vbLabelText   $csharpLabel

ドキュメント読み込み方法の変更

// PdfiumViewer
PdfDocument.Load(path)

// IronPDF
PdfDocument.FromFile(path)
// PdfiumViewer
PdfDocument.Load(path)

// IronPDF
PdfDocument.FromFile(path)
' PdfiumViewer
PdfDocument.Load(path)

' IronPDF
PdfDocument.FromFile(path)
$vbLabelText   $csharpLabel

保存メソッドの変更

//PdfiumViewer(takes a Stream)
document.Save(stream)

//IronPDF(takes a path)
pdf.SaveAs(path)
//PdfiumViewer(takes a Stream)
document.Save(stream)

//IronPDF(takes a path)
pdf.SaveAs(path)
' PdfiumViewer (takes a Stream)
document.Save(stream)

' IronPDF (takes a path)
pdf.SaveAs(path)
$vbLabelText   $csharpLabel

廃棄パターンの簡略化

// PdfiumViewer: explicit disposal of document and the rendered Image
using (var document = PdfDocument.Load(path))
using (var bitmap = document.Render(0, 1024, 768, 96, 96, PdfRenderFlags.None))
{
    bitmap.Save("output.png");
}

// IronPDF: Simplified
var pdf = PdfDocument.FromFile(path);
pdf.RasterizeToImageFiles("output.png");
// PdfiumViewer: explicit disposal of document and the rendered Image
using (var document = PdfDocument.Load(path))
using (var bitmap = document.Render(0, 1024, 768, 96, 96, PdfRenderFlags.None))
{
    bitmap.Save("output.png");
}

// IronPDF: Simplified
var pdf = PdfDocument.FromFile(path);
pdf.RasterizeToImageFiles("output.png");
Imports PdfiumViewer

' PdfiumViewer: explicit disposal of document and the rendered Image
Using document = PdfDocument.Load(path)
    Using bitmap = document.Render(0, 1024, 768, 96, 96, PdfRenderFlags.None)
        bitmap.Save("output.png")
    End Using
End Using

' IronPDF: Simplified
Dim pdf = PdfDocument.FromFile(path)
pdf.RasterizeToImageFiles("output.png")
$vbLabelText   $csharpLabel

プラットフォーム固有のコードの削除

// PDFium wrapper: required platform detection / RID-specific binaries
#if WIN64
    // Load x64 pdfium.dll
#else
    // Load x86 pdfium.dll
#endif

// IronPDF: Remove all platform-specific code
// Just use the API directly
// PDFium wrapper: required platform detection / RID-specific binaries
#if WIN64
    // Load x64 pdfium.dll
#else
    // Load x86 pdfium.dll
#endif

// IronPDF: Remove all platform-specific code
// Just use the API directly
$vbLabelText   $csharpLabel

機能比較の概要

フィーチャー PDFium .NET ラッパー IronPDF
PDFを読み込む はい はい
画像にレンダリング はい はい
テキストの抽出 はい(基本的な、1ページごと) はい(論理順序 / 視覚順序)
ページ情報 はい はい
HTMLから作成 None はい
URLから作成 None はい
PDFのマージ 無料ラッパー:なし; Patagames:部分的 はい
PDFの分割 無料ラッパー:なし; Patagames:部分的 はい
透かしの追加 ビルトインではない はい
ヘッダー/フッター ビルトインではない はい
フォーム入力 無料ラッパー: いいえ; Patagames: はい はい
デジタル署名 無料ラッパー: いいえ; Patagames: はい はい
パスワード保護 無料ラッパー: いいえ; Patagames: はい はい
ネイティブの依存関係 必須 バンドル / NuGet管理
クロスプラットフォーム 複雑な(ペーRIDネイティブバイナリ) 自動翻訳
メモリ管理 マニュアルの廃棄 簡略化

移行チェックリスト

移行前

どのPDFiumラッパーが使用されているかを特定する (PdfiumViewer / PdfiumViewer.Updated / PDFiumCore / Pdfium.Net.SDK) 現在のレンダリング寸法/DPI/スケールを文書化する プロジェクトでのネイティブバイナリの場所を一覧表示(各RIDごと)

  • プラットフォーム固有の読み込みコードを確認する
  • PDF 作成のニーズを特定します (現在別のツールを使用していますか?)
  • 転換のための廃棄パターンを確認する
  • IronPDFライセンスキーを取得する

パッケージの変更

  • PDFiumラッパーNuGetパッケージを削除します:Pdfium.Net.SDK
  • pdfium.dll / .so / .dylib のネイティブバイナリをruntimes/フォルダから削除します
  • プラットフォーム固有の条件付きコンパイルを削除
  • .csproj を更新してネイティブバイナリ参照を削除します
  • IronPdf NuGetパッケージをインストールします:dotnet add package IronPdf

コードの変更

  • 起動時にライセンスキー設定を追加する
  • PdfDocument.Load()PdfDocument.FromFile() に置き換えます
  • document.Save()pdf.SaveAs() に置き換えます
  • document.GetPdfText(i) ループを pdf.ExtractAllText() に置き換えます
  • スケール係数をDPI値に変換します(DPI = 72 × スケール)
  • 破棄パターンを簡素化する(ネストされた using ステートメントを削除する)
  • プラットフォーム固有のコードを削除する

移行後

  • レンダリング出力品質のテスト
  • テキスト抽出結果を比較する
  • クロスプラットフォーム展開のテスト
  • 新しい機能の追加(HTMLからPDFへの変換、結合、透かし、セキュリティ)
  • ドキュメントの更新

ご注意PDFium は、Google LLC のプロジェクトであり、BSD-3-Clauseのもとで公開されています。 PdfiumViewer、PDFiumCore、および Pdfium.Net.SDK は、それぞれの所有者(pvginkel、Dtronix、Patagames Software Ltd)の商標です。 このサイトは、Google、Chromium Project、またはラッパー作成者のいずれとも提携、承認、または後援されていません。 すべての製品名、ロゴ、およびブランドは各所有者の所有物です。 比較は情報提供のみを目的としており、執筆時点で公開されている情報を反映しています。

Curtis Chau
テクニカルライター

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

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

アイアンサポートチーム

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