PDF のフォントを設定する方法 C#
PdfiumViewerからIronPDFへの移行により、Windows Formsビューア/レンダラであるGoogleのPDFiumのラッパーから、ネイティブバイナリ依存関係とページレベルのテキスト抽出のみを持つ.NET PDFワークフローが、すべて for .NETアプリケーションタイプで作成、操作、完全なテキスト抽出、レンダリングを行う包括的なPDFソリューションに移行できます。このガイドは、プラットフォームの制限を排除し、PdfiumViewerでは提供できなかった機能を追加しながら、完全で段階的な移行パスを提供します。
なぜPdfiumViewerからIronPDFに移行するのか
PdfiumViewerを理解する
PdfiumViewer (NuGetパッケージPdfiumViewer、リポジトリpvginkel/PdfiumViewer、Apache 2.0)は、GoogleのPDFiumレンダリングエンジンをラップした.NETのライブラリです。このエンジンはChromeにも使用されており、Windows FormsアプリケーションのためにPDFの閲覧とラスタライズを提供します。
PdfiumViewerはビューアおよびレンダラーであり、ジェネレーターではありません。 PDFの作成、編集、操作をサポートしておらず、そのテキストAPI(PdfDocument.GetPdfText(int page))はレイアウトなしでページテキストの生テキストを返し、単語ごとの座標を提供しません。 上流のリポジトリは2019年8月2日にメンテナーによってアーカイブされ、最後のNuGetリリース(2.13.0)は2017年11月6日に出荷されました。既存のコードは引き続き動作しますが、今後の修正、.NET 6以降の更新、またはCVEパッチは予定されていません。
PdfiumViewerの重要な制限事項
-
ビューア / レンダラーのみ: HTML、画像、またはプログラムによるPDFの作成はできません。 PdfiumViewerの機能は閲覧とラスタライズに限られており、PDFの作成、編集、結合、その他の操作機能をサポートしていません。
-
Windows Forms / Windows専用:
System.DrawingおよびWinFormsコントロールを中心に構築されています。 他のUIフレームワーク用に設計されておらず、System.Drawing.Commonは.NET 6+でWindows専用です。 -
PDFの操作不可: PDFコンテンツの結合、分割、または変更ができません。
-
ネイティブバイナリ依存性: プラットフォーム固有のPDFiumバイナリを
PdfiumViewer.Native.x86_64.v8-xfa経由で必要とします(またはno-V8 / no-XFAバリアント)。 -
上流のアーカイブ: リポジトリは2019-08-02にアーカイブされました; 最新のNuGetリリース 2.13.0 (2017年11月6日); これ以上の更新はありません。
-
ページレベルでのテキスト抽出のみ:
PdfDocument.GetPdfText(int page)は生のページテキストを返し、単語ごとの座標なしでレイアウトの再構築も行わず、画像のみのPDFに対してOCRも行いません。 -
HTML を PDF に変換できません: PDFium は HTML を解析しません。 HTMLからPDFを生成するには、別途ジェネレーター(wkhtmltopdf、IronPDF、PuppeteerSharpなど)が必要であり、その結果を表示またはラスタライズのためにPdfiumViewerで読み込むことができます。
-
ヘッダー/フッターなし: ページ番号や繰り返しのコンテンツを追加できません。
-
透かしなし: ドキュメントにオーバーレイをスタンプすることはできません。
- セキュリティ機能なし: PDFを暗号化またはパスワード保護することはできません。
PdfiumViewerとIronPDFの比較
| アスペクト | PdfiumViewer | IronPDF |
|---|---|---|
| 主な焦点 | WinFormsのPDFビューア | 完全なPDFソリューション |
| ライセンス | アパッチ2.0 | 商用 |
| PDFの作成。 | ✗ | (HTML, URL, 画像) |
| PDF操作 | ✗ | マージ、分割、編集 |
| HTMLからPDFへ | ✗ | Chromium エンジン |
| テキスト抽出。 | ページレベルのみ(GetPdfText) |
フル(レイアウト、ページごと) |
| ウォーターマーク。 | ✗ | ✓ |
| ヘッダー/フッター | ✗ | ✓ |
| セキュリティ。 | ✗ | ✓ |
| 内蔵ビューア | ✓ | ✗ (バックエンド中心) |
| プラットフォームサポート | Windows / WinForms のみ | コンソール、Web、デスクトップ、クロスプラットフォーム |
| フレームワークサポート | .NET Framework 2.0+ | .NET Framework、Core、5以上 |
| メンテナンス | アーカイブ済み 2019-08-02 (最終リリース 2017-11-06) | 活発 |
現代 for .NETをターゲットにするチームに向けて、IronPDFは包括的で積極的にメンテナンスされている基盤を提供します。これにより、すべて for .NETアプリケーションタイプで動作するようになり、Windows Formsの制限やネイティブバイナリの複雑さが解消されます。
始める前に
前提条件
- .NET環境: .NET Framework 4.6.2+ または.NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGetアクセス: NuGetパッケージをインストールする機能
- IronPDFライセンス: IronPDFからライセンスキーを取得します。
NuGetパッケージの変更
# RemovePdfiumViewerpackages
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Native.x86.v8-xfa
dotnet remove package PdfiumViewer.Native.x86_64.v8-xfa
# Install IronPDF
dotnet add package IronPdf
# RemovePdfiumViewerpackages
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Native.x86.v8-xfa
dotnet remove package PdfiumViewer.Native.x86_64.v8-xfa
# Install IronPDF
dotnet add package IronPdf
ライセンス構成
// 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"
PdfiumViewerの使用法を特定する
# FindPdfiumViewerusage
grep -r "PdfiumViewer\|PdfViewer\|PdfDocument\.Load" --include="*.cs" .
# Find native binary references
grep -r "pdfium\.dll\|Native\.x86\|Native\.x64" --include="*.csproj" .
# Find viewer control usage
grep -r "PdfViewer" --include="*.cs" --include="*.Designer.cs" .
# FindPdfiumViewerusage
grep -r "PdfiumViewer\|PdfViewer\|PdfDocument\.Load" --include="*.cs" .
# Find native binary references
grep -r "pdfium\.dll\|Native\.x86\|Native\.x64" --include="*.csproj" .
# Find viewer control usage
grep -r "PdfViewer" --include="*.cs" --include="*.Designer.cs" .
完全な API リファレンス
名前空間の変更
// PdfiumViewer
using PdfiumViewer;
// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// PdfiumViewer
using PdfiumViewer;
// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
Imports PdfiumViewer
Imports IronPdf
Imports IronPdf.Rendering
Imports IronPdf.Editing
コア クラス マッピング
| PdfiumViewer | IronPDF |
|---|---|
PdfDocument |
PdfDocument |
PdfViewer |
(同等のものはありません)_ |
PdfRenderer |
ChromePdfRenderer |
| (利用できません) | HtmlHeaderFooter |
ドキュメント読み込みマッピング
| PdfiumViewer | IronPDF |
|---|---|
PdfDocument.Load(path) |
PdfDocument.FromFile(path) |
PdfDocument.Load(stream) |
PdfDocument.FromStream(stream) |
PdfDocument.Load(path, password) |
PdfDocument.FromFile(path, password) |
| (バイトオーバーロードなし - MemoryStream でラップ) | PdfDocument.FromBinaryData(bytes) |
ドキュメント プロパティのマッピング
| PdfiumViewer | IronPDF |
|---|---|
document.PageCount |
document.PageCount |
document.PageSizes[i] |
document.Pages[i].Width/Height |
document.GetPdfText(pageIndex) |
pdf.Pages[pageIndex].Text |
ページ レンダリング マッピング
| PdfiumViewer | IronPDF |
|---|---|
document.Render(pageIndex, dpiX, dpiY, forPrinting) |
pdf.ToBitmap(pageIndex) |
document.Render(pageIndex, width, height, dpiX, dpiY, flags) |
pdf.RasterizeToImageFiles(path, dpi) |
ドキュメント マッピングの保存
| PdfiumViewer | IronPDF |
|---|---|
document.Save(path) |
pdf.SaveAs(path) |
document.Save(stream) |
new MemoryStream(pdf.BinaryData) |
| (利用できません) | pdf.BinaryData (byte[]を返す) |
PdfiumViewerと比較した新機能および大幅に拡張された機能
| IronPDFの特徴 | 翻訳内容 |
|---|---|
pdf.ExtractAllText() |
ドキュメント全体のテキスト抽出(PdfiumViewerはページレベルGetPdfTextのみを提供) |
pdf.ExtractTextFromPage(index) |
特定のページからテキストを抽出 |
ChromePdfRenderer.RenderHtmlAsPdf() |
HTMLから作成 |
ChromePdfRenderer.RenderUrlAsPdf() |
URLから作成 |
PdfDocument.Merge() |
PDFの結合 |
pdf.CopyPages() |
ページの抜粋 |
pdf.RemovePages() |
ページの削除 |
pdf.ApplyWatermark() |
透かしの追加 |
pdf.AddHtmlHeaders() |
ヘッダーの追加 |
pdf.AddHtmlFooters() |
フッターの追加 |
pdf.SecuritySettings |
パスワード保護 |
pdf.Form |
フォーム入力 |
コード移行の例
例1: PDFからのテキスト抽出
翻訳前 (PdfiumViewer):
// NuGet: Install-Package PdfiumViewer
// Install-Package PdfiumViewer.Native.x86.v8-xfa
// Install-Package PdfiumViewer.Native.x86_64.v8-xfa
using PdfiumViewer;
using System;
using System.Text;
string pdfPath = "document.pdf";
//PdfiumViewerexposes page-level text extraction via
// PdfDocument.GetPdfText(int page). It returns raw page text only —
// no layout, no per-word coordinates, no OCR for image-only pages.
using (var document = PdfDocument.Load(pdfPath))
{
int pageCount = document.PageCount;
Console.WriteLine($"Total pages: {pageCount}");
var sb = new StringBuilder();
for (int i = 0; i < pageCount; i++)
{
string pageText = document.GetPdfText(i);
sb.AppendLine($"--- Page {i + 1} ---");
sb.AppendLine(pageText);
}
Console.WriteLine(sb.ToString());
}
// NuGet: Install-Package PdfiumViewer
// Install-Package PdfiumViewer.Native.x86.v8-xfa
// Install-Package PdfiumViewer.Native.x86_64.v8-xfa
using PdfiumViewer;
using System;
using System.Text;
string pdfPath = "document.pdf";
//PdfiumViewerexposes page-level text extraction via
// PdfDocument.GetPdfText(int page). It returns raw page text only —
// no layout, no per-word coordinates, no OCR for image-only pages.
using (var document = PdfDocument.Load(pdfPath))
{
int pageCount = document.PageCount;
Console.WriteLine($"Total pages: {pageCount}");
var sb = new StringBuilder();
for (int i = 0; i < pageCount; i++)
{
string pageText = document.GetPdfText(i);
sb.AppendLine($"--- Page {i + 1} ---");
sb.AppendLine(pageText);
}
Console.WriteLine(sb.ToString());
}
Imports PdfiumViewer
Imports System
Imports System.Text
Dim pdfPath As String = "document.pdf"
' PdfiumViewer exposes page-level text extraction via
' PdfDocument.GetPdfText(Integer page). It returns raw page text only —
' no layout, no per-word coordinates, no OCR for image-only pages.
Using document As PdfDocument = PdfDocument.Load(pdfPath)
Dim pageCount As Integer = document.PageCount
Console.WriteLine($"Total pages: {pageCount}")
Dim sb As New StringBuilder()
For i As Integer = 0 To pageCount - 1
Dim pageText As String = document.GetPdfText(i)
sb.AppendLine($"--- Page {i + 1} ---")
sb.AppendLine(pageText)
Next
Console.WriteLine(sb.ToString())
End Using
翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
string pdfPath = "document.pdf";
// Open and extract text from PDF
PdfDocument pdf = PdfDocument.FromFile(pdfPath);
// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);
// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst page text: {pageText}");
Console.WriteLine($"\nTotal pages: {pdf.PageCount}");
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
string pdfPath = "document.pdf";
// Open and extract text from PDF
PdfDocument pdf = PdfDocument.FromFile(pdfPath);
// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);
// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst page text: {pageText}");
Console.WriteLine($"\nTotal pages: {pdf.PageCount}");
Imports IronPdf
Imports System
Module Program
Sub Main()
Dim pdfPath As String = "document.pdf"
' Open and extract text from PDF
Dim pdf As PdfDocument = PdfDocument.FromFile(pdfPath)
' Extract text from all pages
Dim allText As String = pdf.ExtractAllText()
Console.WriteLine("Extracted Text:")
Console.WriteLine(allText)
' Extract text from specific page
Dim pageText As String = pdf.ExtractTextFromPage(0)
Console.WriteLine(vbCrLf & "First page text: " & pageText)
Console.WriteLine(vbCrLf & "Total pages: " & pdf.PageCount)
End Sub
End Module
PdfiumViewerのテキストAPIはPdfDocument.GetPdfText(int page)で、ページレベルの生テキストのみを返し、レイアウトの再構築や単語ごとの座標を提供せず、画像のみのPDFに対するOCRのフォールバックも行いません。 フラットテキストのダンプを超えるものは、カスタムレイアウトのヒューリスティックまたは異なるライブラリが必要です。
IronPDFはExtractTextFromPage(index) (またはpdf.Pages[index].Text)を通じて行います。 追加オプションについては、テキスト抽出のドキュメントを参照してください。
例2: HTMLからPDFへの変換
翻訳前 (PdfiumViewer):
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
//PdfiumViewerwraps Google's PDFium — a renderer, not a generator.
// PDFium does not parse HTML, soPdfiumViewerhas no HTML-to-PDF path.
// To produce a PDF from HTML you need a separate generator (wkhtmltopdf,
// IronPDF, PuppeteerSharp, etc.), then load the result with PdfiumViewer
// for display or rasterization.
string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";
// Pretend "output.pdf" was produced by another tool — load and render it.
string existingPdfPath = "output.pdf";
using (var document = PdfDocument.Load(existingPdfPath))
{
Console.WriteLine($"Loaded PDF with {document.PageCount} page(s).");
// PdfDocument.Render(int page, float dpiX, float dpiY, bool forPrinting)
var image = document.Render(0, 300, 300, true);
Console.WriteLine("Rendered page 1 at 300 DPI.");
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
//PdfiumViewerwraps Google's PDFium — a renderer, not a generator.
// PDFium does not parse HTML, soPdfiumViewerhas no HTML-to-PDF path.
// To produce a PDF from HTML you need a separate generator (wkhtmltopdf,
// IronPDF, PuppeteerSharp, etc.), then load the result with PdfiumViewer
// for display or rasterization.
string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";
// Pretend "output.pdf" was produced by another tool — load and render it.
string existingPdfPath = "output.pdf";
using (var document = PdfDocument.Load(existingPdfPath))
{
Console.WriteLine($"Loaded PDF with {document.PageCount} page(s).");
// PdfDocument.Render(int page, float dpiX, float dpiY, bool forPrinting)
var image = document.Render(0, 300, 300, true);
Console.WriteLine("Rendered page 1 at 300 DPI.");
}
Imports PdfiumViewer
Imports System
' PdfiumViewer wraps Google's PDFium — a renderer, not a generator.
' PDFium does not parse HTML, so PdfiumViewer has no HTML-to-PDF path.
' To produce a PDF from HTML you need a separate generator (wkhtmltopdf,
' IronPDF, PuppeteerSharp, etc.), then load the result with PdfiumViewer
' for display or rasterization.
Dim htmlContent As String = "<h1>Hello World</h1><p>This is a test document.</p>"
' Pretend "output.pdf" was produced by another tool — load and render it.
Dim existingPdfPath As String = "output.pdf"
Using document As PdfDocument = PdfDocument.Load(existingPdfPath)
Console.WriteLine($"Loaded PDF with {document.PageCount} page(s).")
' PdfDocument.Render(int page, float dpiX, float dpiY, bool forPrinting)
Dim image = document.Render(0, 300, 300, True)
Console.WriteLine("Rendered page 1 at 300 DPI.")
End Using
翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";
// Create a PDF from HTML string
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Save the PDF
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
string htmlContent = "<h1>Hello World</h1><p>This is a test document.</p>";
// Create a PDF from HTML string
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Save the PDF
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
Imports IronPdf
Imports System
Module Program
Sub Main()
Dim htmlContent As String = "<h1>Hello World</h1><p>This is a test document.</p>"
' Create a PDF from HTML string
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
' Save the PDF
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully!")
End Sub
End Module
これが最大の機能ギャップです。PDFiumはHTMLを解析しないため、PdfiumViewerにはHTMLからPDFへのパスがありません。最初に別のツールでPDFを生成し、その後PdfiumViewerを使用して表示またはラスタライズします。
IronPDFはChromePdfRendererを通してネイティブなHTMLからPDFへの変換を提供し、内部的にHTML、CSS、JavaScriptのレンダリングにはChromiumエンジンを使用しています。 RenderHtmlFileAsPdf()はHTMLファイルを読み込みます。 包括的な例については、HTML to PDF documentationを参照してください。
例3: PDFから画像への変換
翻訳前 (PdfiumViewer):
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.Drawing;
using System.Drawing.Imaging;
string pdfPath = "document.pdf";
string outputImage = "page1.png";
// PDFiumViewer excels at rendering PDFs to images
using (var document = PdfDocument.Load(pdfPath))
{
// Render first page at 300 DPI
int dpi = 300;
using (var image = document.Render(0, dpi, dpi, true))
{
// Save as PNG
image.Save(outputImage, ImageFormat.Png);
Console.WriteLine($"Page rendered to {outputImage}");
}
// Render all pages
for (int i = 0; i < document.PageCount; i++)
{
using (var pageImage = document.Render(i, 150, 150, true))
{
pageImage.Save($"page_{i + 1}.png", ImageFormat.Png);
}
}
}
// NuGet: Install-Package PdfiumViewer
using PdfiumViewer;
using System;
using System.Drawing;
using System.Drawing.Imaging;
string pdfPath = "document.pdf";
string outputImage = "page1.png";
// PDFiumViewer excels at rendering PDFs to images
using (var document = PdfDocument.Load(pdfPath))
{
// Render first page at 300 DPI
int dpi = 300;
using (var image = document.Render(0, dpi, dpi, true))
{
// Save as PNG
image.Save(outputImage, ImageFormat.Png);
Console.WriteLine($"Page rendered to {outputImage}");
}
// Render all pages
for (int i = 0; i < document.PageCount; i++)
{
using (var pageImage = document.Render(i, 150, 150, true))
{
pageImage.Save($"page_{i + 1}.png", ImageFormat.Png);
}
}
}
Imports PdfiumViewer
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Module Module1
Sub Main()
Dim pdfPath As String = "document.pdf"
Dim outputImage As String = "page1.png"
' PDFiumViewer excels at rendering PDFs to images
Using document = PdfDocument.Load(pdfPath)
' Render first page at 300 DPI
Dim dpi As Integer = 300
Using image = document.Render(0, dpi, dpi, True)
' Save as PNG
image.Save(outputImage, ImageFormat.Png)
Console.WriteLine($"Page rendered to {outputImage}")
End Using
' Render all pages
For i As Integer = 0 To document.PageCount - 1
Using pageImage = document.Render(i, 150, 150, True)
pageImage.Save($"page_{i + 1}.png", ImageFormat.Png)
End Using
Next
End Using
End Sub
End Module
翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Linq;
string pdfPath = "document.pdf";
string outputImage = "page1.png";
// Open PDF and convert to images
PdfDocument pdf = PdfDocument.FromFile(pdfPath);
// Convert first page to image
var firstPageImage = pdf.ToBitmap(0);
firstPageImage[0].Save(outputImage);
Console.WriteLine($"Page rendered to {outputImage}");
// Convert all pages to images
var allPageImages = pdf.ToBitmap();
for (int i = 0; i < allPageImages.Length; i++)
{
allPageImages[i].Save($"page_{i + 1}.png");
Console.WriteLine($"Saved page {i + 1}");
}
Console.WriteLine($"Total pages converted: {pdf.PageCount}");
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Linq;
string pdfPath = "document.pdf";
string outputImage = "page1.png";
// Open PDF and convert to images
PdfDocument pdf = PdfDocument.FromFile(pdfPath);
// Convert first page to image
var firstPageImage = pdf.ToBitmap(0);
firstPageImage[0].Save(outputImage);
Console.WriteLine($"Page rendered to {outputImage}");
// Convert all pages to images
var allPageImages = pdf.ToBitmap();
for (int i = 0; i < allPageImages.Length; i++)
{
allPageImages[i].Save($"page_{i + 1}.png");
Console.WriteLine($"Saved page {i + 1}");
}
Console.WriteLine($"Total pages converted: {pdf.PageCount}");
Imports IronPdf
Imports System
Imports System.Linq
Module Module1
Sub Main()
Dim pdfPath As String = "document.pdf"
Dim outputImage As String = "page1.png"
' Open PDF and convert to images
Dim pdf As PdfDocument = PdfDocument.FromFile(pdfPath)
' Convert first page to image
Dim firstPageImage = pdf.ToBitmap(0)
firstPageImage(0).Save(outputImage)
Console.WriteLine($"Page rendered to {outputImage}")
' Convert all pages to images
Dim allPageImages = pdf.ToBitmap()
For i As Integer = 0 To allPageImages.Length - 1
allPageImages(i).Save($"page_{i + 1}.png")
Console.WriteLine($"Saved page {i + 1}")
Next
Console.WriteLine($"Total pages converted: {pdf.PageCount}")
End Sub
End Module
これは、PdfiumViewerが得意とする分野です。画像へのPDFレンダリングは、PdfiumViewerの最大の強みです。 どちらのライブラリもこのタスクを効果的に処理しますが、パターンは異なります。
PdfiumViewerはusingステートメントを使用します。 System.Drawing.Imagingをインポートする必要があります。
IronPDFはpdf.ToBitmap(pageIndex)を使用し、ビットマップ配列を返します。 ネストされた廃棄要件はなく、よりシンプルなパターンです。 バッチ操作のために、引数なしのToBitmap()はすべてのページを返します。 直接的なファイル出力にはRasterizeToImageFiles()を使用することもできます。 その他のレンダリングオプションについては、PDF to image documentationを参照してください。
ネイティブ依存性の除去
PdfiumViewerからIronPDFへの移行の大きな利点のひとつは、ネイティブのバイナリ管理が不要になることです。
ビフォア (PdfiumViewer) - 複雑なデプロイ
MyApp/
├── ビン/
│ ├──MyApp.dll
│ ├──PdfiumViewer.dll
│ ├── x86/
│ └── pdfium.dll
│ └── x64/
└─ pdfium.dll
翻訳後 (IronPDF) - クリーンなデプロイメント
MyApp/
├── ビン/
│ ├──MyApp.dll
│ └─ IronPDF.dll # 含まれるものすべて
ネイティブ バイナリ参照の削除
# Delete native PDFium binaries
rm -rf x86/x64/runtimes/
# Remove from .csproj native package references
# <PackageReference Include="PdfiumViewer.Native.x86.v8-xfa" />
# <PackageReference Include="PdfiumViewer.Native.x64.v8-xfa" />
# Delete native PDFium binaries
rm -rf x86/x64/runtimes/
# Remove from .csproj native package references
# <PackageReference Include="PdfiumViewer.Native.x86.v8-xfa" />
# <PackageReference Include="PdfiumViewer.Native.x64.v8-xfa" />
重要な移行に関する注意事項
組み込みのビューア コントロールはありません
IronPDFはバックエンドに特化しており、ビジュアルPDFビューアコントロールは含まれていません:
// PdfiumViewer: Built-in viewer control
pdfViewer.Document = document;
// IronPDF: Use external viewer or web-based approach
pdf.SaveAs(tempPath);
Process.Start(new ProcessStartInfo(tempPath) { UseShellExecute = true });
// PdfiumViewer: Built-in viewer control
pdfViewer.Document = document;
// IronPDF: Use external viewer or web-based approach
pdf.SaveAs(tempPath);
Process.Start(new ProcessStartInfo(tempPath) { UseShellExecute = true });
' PdfiumViewer: Built-in viewer control
pdfViewer.Document = document
' IronPDF: Use external viewer or web-based approach
pdf.SaveAs(tempPath)
Process.Start(New ProcessStartInfo(tempPath) With {.UseShellExecute = True})
閲覧の必要がある場合、Process.Start()を使用してデフォルトのPDFビューアで開くか、PDFパス付きのWebBrowserコントロールやSyncfusion、DevExpress、Telerikなどのサードパーティのビューアコントロールを検討してください。
ドキュメント読み込み方法の変更
// PdfiumViewer
PdfDocument.Load(path)
// IronPDF
PdfDocument.FromFile(path)
// PdfiumViewer
PdfDocument.Load(path)
// IronPDF
PdfDocument.FromFile(path)
' PdfiumViewer
PdfDocument.Load(path)
' IronPDF
PdfDocument.FromFile(path)
保存メソッドの変更
// PdfiumViewer
document.Save(path)
// IronPDF
pdf.SaveAs(path)
// PdfiumViewer
document.Save(path)
// IronPDF
pdf.SaveAs(path)
レンダー メソッドの変更
// PdfiumViewer: Returns image with nested using
using (var image = document.Render(0, 150, 150, true))
{
image.Save("page.png", ImageFormat.Png);
}
// IronPDF: Returns bitmap array
var images = pdf.ToBitmap(0);
images[0].Save("page.png");
// PdfiumViewer: Returns image with nested using
using (var image = document.Render(0, 150, 150, true))
{
image.Save("page.png", ImageFormat.Png);
}
// IronPDF: Returns bitmap array
var images = pdf.ToBitmap(0);
images[0].Save("page.png");
Imports System.Drawing.Imaging
' PdfiumViewer: Returns image with nested using
Using image = document.Render(0, 150, 150, True)
image.Save("page.png", ImageFormat.Png)
End Using
' IronPDF: Returns bitmap array
Dim images = pdf.ToBitmap(0)
images(0).Save("page.png")
ページ サイズ アクセス変更
// PdfiumViewer
var size = document.PageSizes[index];
Console.WriteLine($"{size.Width} x {size.Height}");
// IronPDF
var page = pdf.Pages[index];
Console.WriteLine($"{page.Width} x {page.Height}");
// PdfiumViewer
var size = document.PageSizes[index];
Console.WriteLine($"{size.Width} x {size.Height}");
// IronPDF
var page = pdf.Pages[index];
Console.WriteLine($"{page.Width} x {page.Height}");
' PdfiumViewer
Dim size = document.PageSizes(index)
Console.WriteLine($"{size.Width} x {size.Height}")
' IronPDF
Dim page = pdf.Pages(index)
Console.WriteLine($"{page.Width} x {page.Height}")
機能比較の概要
| フィーチャー | PdfiumViewer | IronPDF |
|---|---|---|
| PDFを読み込む | ✓ | ✓ |
| 画像にレンダリング | ✓ | ✓ |
| 内蔵ビューア | ✓ | ✗ |
| 印刷用PDF | ✓ | ✓ |
| テキストの抽出 | ページレベル(GetPdfText) |
完全(ExtractAllText、ページごと) |
| HTMLから作成 | ✗ | ✓ |
| URLから作成 | ✗ | ✓ |
| PDFのマージ | ✗ | ✓ |
| PDFの分割 | ✗ | ✓ |
| 透かしの追加 | ✗ | ✓ |
| ヘッダー/フッター | ✗ | ✓ |
| フォーム入力 | ✗ | ✓ |
| パスワード保護 | ✗ | ✓ |
| WinFormsサポート | ✓ | ✓ |
| ASP.NETサポート | ✗ | ✓ |
| .NET Coreサポート | 制限付き (System.DrawingはWindowsに縛られています) | ✓ |
| アクティブメンテナンス | 2019-08-02 にアーカイブされました | ✓ |
移行チェックリスト
移行前
- コードベース内のすべてのPdfiumViewerの使用箇所を特定する
- PdfViewer コントロールを使用して WinForms を一覧表示する
- 現在のレンダリングDPI設定を文書化する
- ネイティブバイナリ参照をチェックする
- 印刷機能の使用状況を特定する
- プランビューアコントロールの置き換え戦略
- IronPDFライセンスキーを取得する
パッケージの変更
PdfiumViewerNuGetパッケージを削除PdfiumViewer.Native.x86.v8-xfaパッケージを削除PdfiumViewer.Native.x86_64.v8-xfaパッケージを削除- x86/ および x64/ フォルダからネイティブ pdfium.dll バイナリを削除します
IronPdfNuGetパッケージをインストール:dotnet add package IronPdf
コードの変更
- 起動時にライセンスキー設定を追加する
PdfDocument.Load()をPdfDocument.FromFile()に置き換えるdocument.Save()をpdf.SaveAs()に置き換えるdocument.Render()をpdf.ToBitmap()またはRasterizeToImageFiles()に置き換えるdocument.PageSizes[i]をpdf.Pages[i].Width/Heightに置き換える- PdfViewer コントロールを外部ビューアまたは Process.Start() に置き換えます
- 新しい機能の追加 (テキスト抽出、HTML から PDF など)
移行後
- レンダリング出力品質のテスト
- 印刷機能のテスト
- ターゲットプラットフォームでのテスト
- 新しい機能の追加(HTMLからPDFへの変換、結合、透かし、セキュリティ)
- ドキュメントの更新

