C#でSumatra PDFからIronPDFへ移行する方法
Sumatra PDFからIronPDFへの移行は、PDFワークフローをデスクトップビューアアプリケーションによる外部プロセス管理から、完全なPDF作成、操作、抽出機能を備えた.NETネイティブライブラリ統合へと変えます。 このガイドは、外部依存、GPLライセンスの制限、そしてSumatra PDFが開発ライブラリではなくビューアであるという基本的な制限を排除した、完全でステップバイステップの移行パスを提供します。
なぜスマトラPDFからIronPDFへ移行するのか
スマトラを理解する PDF
Sumatra PDFは、主に軽量なオープンソースのPDFリーダーで、そのシンプルさとスピードで有名です。 しかし、Sumatra PDFは、PDFファイルを閲覧するだけでなく、PDFファイルの作成や操作に必要な機能を提供していません。 PDFを読むための無料で多用途なオプションとして、飾り気のない体験を求める多くのユーザーに愛用されています。 しかし、アプリケーション内での作成やライブラリ統合のような、より包括的なPDF機能を必要とする開発者に関しては、Sumatra PDFは、その固有の設計上の制限のために不足しています。
Sumatra PDFはデスクトップPDFビューアアプリケーションであり、開発ライブラリではありません。 .NETアプリケーションでSumatra PDFを使用している場合、おそらく次のようなことが考えられます:
1.PDFを表示する外部プロセスとして起動する 2.コマンドラインでPDFを印刷する 3.ユーザーがインストールしなければならない依存関係として、このツールに依存してください。
スマトラPDF統合の主な問題点
| 課題 | インパクト |
|---|---|
| ライブラリではありません。 | プログラムによるPDFの作成や編集はできません。 |
| 外部プロセスの場合 | 別プロセスの起動が必要 |
| GPLライセンス。 | 商用ソフトウェアに対する制限 |
| ユーザー依存性 | ユーザーはSumatraを別途インストールする必要があります。 |
| APIはありません。 | コマンドライン引数に限定 |
| 閲覧のみ。 | PDFの作成、編集、操作はできません。 |
| ウェブサポートはありません。 | デスクトップ専用アプリケーション |
スマトラPDFとIronPDFの比較
| フィーチャー | スマトラPDF | IronPDF |
|---|---|---|
| タイプ | アプリケーション | ライブラリ |
| PDFリーディング | はい | はい |
| PDFの作成。 | なし | はい |
| PDFの編集。 | なし | はい |
| 統合。 | 制限付き(スタンドアロン) | アプリケーションへの完全統合 |
| ライセンス | GPL | 商用 |
| PDFを作成する。 | なし | はい |
| PDFを編集する。 | なし | はい |
| HTMLからPDFへ | なし | はい |
| マージ/スプリット | なし | はい |
| ウォーターマーク。 | なし | はい |
| デジタル署名。 | なし | はい |
| フォーム入力 | なし | はい |
| テキスト抽出。 | なし | はい |
| .NETインテグレーション | なし | ネイティブ |
| ウェブアプリケーション。 | なし | はい |
IronPDFはSumatra PDFとは異なり、特定のデスクトップアプリケーションや外部プロセスに縛られることはありません。 C#で直接PDF文書を動的に作成、編集、操作するための柔軟なライブラリを開発者に提供します。 このように外部プロセスから切り離すことで、単純明快で適応性が高く、単に見るだけでなく幅広い用途に適しているという顕著な利点があります。
2025年と2026年まで.NET 10とC# 14の採用を計画しているチームに対して、IronPDFは外部プロセスのオーバーヘッドとSumatra PDFのGPLライセンス制限を排除するネイティブライブラリ統合を提供します。
始める前に
前提条件
- .NET環境: .NET Framework 4.6.2+ または.NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGetアクセス: NuGetパッケージをインストールする機能
- IronPDFライセンス: IronPDFからライセンスキーを取得します。
インストール
# Install IronPDF
dotnet add package IronPdf
# Install IronPDF
dotnet add package IronPdf
ライセンス構成
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
完全な API リファレンス
名前空間の変更
// Before:スマトラPDF(external process)
using System.Diagnostics;
using System.IO;
// After: IronPDF
using IronPdf;
// Before:スマトラPDF(external process)
using System.Diagnostics;
using System.IO;
// After: IronPDF
using IronPdf;
Imports System.Diagnostics
Imports System.IO
Imports IronPdf
コア機能のマッピング
| スマトラPDFアプローチ | IronPDF 同等物 | ノート |
|---|---|---|
Process.Start("SumatraPDF.exe", pdfPath) |
PdfDocument.FromFile() |
PDFを読み込む |
| コマンドライン引数 | ネイティブAPIメソッド | CLI不要 |
外部 pdftotext.exe |
pdf.ExtractAllText() |
テキスト抽出 |
外部 wkhtmltopdf.exe |
renderer.RenderHtmlAsPdf() |
HTMLからPDFへ |
-print-to-default 引数 |
pdf.Print() |
印刷 |
| 不可 | PdfDocument.Merge() |
PDFのマージ |
| 不可 | pdf.ApplyWatermark() |
透かし |
| 不可 | pdf.SecuritySettings |
パスワード保護 |
コード移行の例
例1: HTMLからPDFへの変換
ビフォア(スマトラPDF):
// NuGet: Install-Package SumatraPDF (Note: Sumatra is primarily a viewer, not a generator)
//スマトラPDFdoesn't have direct C# integration forHTMLからPDFへconversion
// You would need to use external tools or libraries and then open with Sumatra
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//スマトラPDFcannot directly convert HTML to PDF
// You'd need to use wkhtmltopdf or similar, then view in Sumatra
string htmlFile = "input.html";
string pdfFile = "output.pdf";
// Using wkhtmltopdf as intermediary
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "wkhtmltopdf.exe",
Arguments = $"{htmlFile} {pdfFile}",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
// Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile);
}
}
// NuGet: Install-Package SumatraPDF (Note: Sumatra is primarily a viewer, not a generator)
//スマトラPDFdoesn't have direct C# integration forHTMLからPDFへconversion
// You would need to use external tools or libraries and then open with Sumatra
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//スマトラPDFcannot directly convert HTML to PDF
// You'd need to use wkhtmltopdf or similar, then view in Sumatra
string htmlFile = "input.html";
string pdfFile = "output.pdf";
// Using wkhtmltopdf as intermediary
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "wkhtmltopdf.exe",
Arguments = $"{htmlFile} {pdfFile}",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
// Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile);
}
}
Imports System.Diagnostics
Imports System.IO
Module Program
Sub Main()
' スマトラPDF cannot directly convert HTML to PDF
' You'd need to use wkhtmltopdf or similar, then view in Sumatra
Dim htmlFile As String = "input.html"
Dim pdfFile As String = "output.pdf"
' Using wkhtmltopdf as intermediary
Dim psi As New ProcessStartInfo With {
.FileName = "wkhtmltopdf.exe",
.Arguments = $"{htmlFile} {pdfFile}",
.UseShellExecute = False
}
Process.Start(psi)?.WaitForExit()
' Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile)
End Sub
End Module
翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string htmlContent = "<h1>Hello World</h1><p>This isHTMLからPDFへconversion.</p>";
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()
{
var renderer = new ChromePdfRenderer();
string htmlContent = "<h1>Hello World</h1><p>This isHTMLからPDFへconversion.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim htmlContent As String = "<h1>Hello World</h1><p>This is HTMLからPDFへ conversion.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully!")
End Sub
End Class
この例は、基本的なアーキテクチャの違いを示しています。 スマトラPDFは、HTMLを直接PDFに変換することはできませんので、wkhtmltopdfのような外部ツールを仲介として使用し、結果を表示するために別のプロセスとしてスマトラを起動する必要があります。 このため、2つの外部実行ファイルと複数のプロセス起動が必要です。
IronPDF は、わずか 3 行のコード内で ChromePdfRenderer と RenderHtmlAsPdf() を使用します。 外部ツール、プロセス管理、中間ファイルは使用しません。 PDF はメモリ内に直接作成され、SaveAs() で保存されます。 包括的な例については、HTML to PDF documentationを参照してください。
例 2:PDFを開いて表示する
ビフォア(スマトラPDF):
// NuGet: Install-Package SumatraPDF.CommandLine (or direct executable)
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
string pdfPath = "document.pdf";
//スマトラPDFexcels at viewing PDFs
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "SumatraPDF.exe",
Arguments = $"\"{pdfPath}\"",
UseShellExecute = true
};
Process.Start(startInfo);
// Optional: Open specific page
// Arguments = $"-page 5 \"{pdfPath}\""
}
}
// NuGet: Install-Package SumatraPDF.CommandLine (or direct executable)
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
string pdfPath = "document.pdf";
//スマトラPDFexcels at viewing PDFs
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "SumatraPDF.exe",
Arguments = $"\"{pdfPath}\"",
UseShellExecute = true
};
Process.Start(startInfo);
// Optional: Open specific page
// Arguments = $"-page 5 \"{pdfPath}\""
}
}
Imports System.Diagnostics
Imports System.IO
Module Program
Sub Main()
Dim pdfPath As String = "document.pdf"
' スマトラPDF excels at viewing PDFs
Dim startInfo As New ProcessStartInfo With {
.FileName = "SumatraPDF.exe",
.Arguments = $"""{pdfPath}""",
.UseShellExecute = True
}
Process.Start(startInfo)
' Optional: Open specific page
' Arguments = $"-page 5 ""{pdfPath}"""
End Sub
End Module
翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}");
//IronPDFcan manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf");
// Open with default PDF viewer
Process.Start(new ProcessStartInfo("modified.pdf") { UseShellExecute = true });
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}");
//IronPDFcan manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf");
// Open with default PDF viewer
Process.Start(new ProcessStartInfo("modified.pdf") { UseShellExecute = true });
}
}
Imports IronPdf
Imports System
Imports System.Diagnostics
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}")
' IronPDF can manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf")
' Open with default PDF viewer
Process.Start(New ProcessStartInfo("modified.pdf") With {.UseShellExecute = True})
End Sub
End Class
Sumatra PDFはPDFの表示に優れていますが、コマンドライン引数で外部プロセスを起動することには制限があります。 プログラムでPDFコンテンツにアクセスすることはできません。
IronPDF は、PdfDocument.FromFile() を使用して PDF を読み込み、完全なプログラム アクセスを提供します。 PageCount のようなプロパティを読み取り、ドキュメントを操作し、変更を保存してから、システムのデフォルトの PDF ビューアで開くことができます。 重要な違いは、IronPDFは単なるプロセス引数ではなく、実際のAPIを提供することです。 詳しくは、チュートリアルをご覧ください。
例3: PDFからテキストを抽出する
ビフォア(スマトラPDF):
//スマトラPDFdoesn't provide C# API for text extraction
// You would need to use command-line tools or other libraries
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//スマトラPDFis a viewer, not a text extraction library
// You'd need to use PDFBox, iTextSharp, or similar for extraction
string pdfFile = "document.pdf";
// This would require external tools like pdftotext
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "pdftotext.exe",
Arguments = $"{pdfFile} output.txt",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
string extractedText = File.ReadAllText("output.txt");
Console.WriteLine(extractedText);
}
}
//スマトラPDFdoesn't provide C# API for text extraction
// You would need to use command-line tools or other libraries
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//スマトラPDFis a viewer, not a text extraction library
// You'd need to use PDFBox, iTextSharp, or similar for extraction
string pdfFile = "document.pdf";
// This would require external tools like pdftotext
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "pdftotext.exe",
Arguments = $"{pdfFile} output.txt",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
string extractedText = File.ReadAllText("output.txt");
Console.WriteLine(extractedText);
}
}
Imports System.Diagnostics
Imports System.IO
Module Program
Sub Main()
'スマトラPDFis a viewer, not a text extraction library
' You'd need to use PDFBox, iTextSharp, or similar for extraction
Dim pdfFile As String = "document.pdf"
' This would require external tools like pdftotext
Dim psi As New ProcessStartInfo With {
.FileName = "pdftotext.exe",
.Arguments = $"{pdfFile} output.txt",
.UseShellExecute = False
}
Process.Start(psi)?.WaitForExit()
Dim extractedText As String = File.ReadAllText("output.txt")
Console.WriteLine(extractedText)
End Sub
End Module
翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// 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:\n{pageText}");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// 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:\n{pageText}");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' 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:" & vbCrLf & pageText)
End Sub
End Class
Sumatra PDF はビューアであり、テキスト抽出ライブラリではありません。 テキストを抽出するには、pdftotext.exe などの外部コマンドライン ツールを使用してプロセスを生成し、それが完了するまで待機し、出力ファイルを読み取り、関連するすべてのファイル I/O とクリーンアップを処理する必要があります。
IronPDF は、ドキュメント全体に対しては ExtractAllText()、特定のページに対しては ExtractTextFromPage(0) を使用してネイティブ テキスト抽出を提供します。 外部プロセス、一時ファイル、クリーンアップは不要です。
機能比較
| フィーチャー | スマトラPDF | IronPDF | |||
|---|---|---|---|---|---|
| :作成: | HTMLからPDFへ | なし | はい | ||
| URLからPDFへ | なし | はい | |||
| テキストからPDFへ | なし | はい | |||
| 画像からPDFへ | なし | はい | |||
| :操作: | PDFのマージ | なし | はい | ||
| PDFの分割 | なし | はい | |||
| ページの回転 | なし | はい | |||
| ページの削除 | なし | はい | |||
| ページの並び替え | なし | はい | |||
| :コンテンツ: | 透かしの追加 | なし | はい | ||
| ヘッダー/フッターの追加 | なし | はい | |||
| スタンプテキスト | なし | はい | |||
| スタンプ画像 | なし | はい | |||
| :安全: | パスワード保護 | なし | はい | ||
| デジタル署名 | なし | はい | |||
| 暗号化 | なし | はい | |||
| 許可設定 | なし | はい | |||
| :抽出: | テキストの抽出 | なし | はい | ||
| 画像の抽出 | なし | はい | |||
| :プラットフォーム: | ウィンドウズ | はい | はい | ||
| Linux | なし | はい | |||
| macOS | なし | はい | |||
| ウェブアプリ | なし | はい | |||
| Azure/AWS | なし | はい |
移行後の新機能
IronPdfに移行した後は、Sumatra PDFでは提供できない機能を得ることができます:
HTMLからのPDF作成
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>");
pdf.SaveAs("invoice.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>");
pdf.SaveAs("invoice.pdf");
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>")
pdf.SaveAs("invoice.pdf")
PDFマージ
var pdf1 = PdfDocument.FromFile("chapter1.pdf");
var pdf2 = PdfDocument.FromFile("chapter2.pdf");
var pdf3 = PdfDocument.FromFile("chapter3.pdf");
var book = PdfDocument.Merge(pdf1, pdf2, pdf3);
book.SaveAs("complete_book.pdf");
var pdf1 = PdfDocument.FromFile("chapter1.pdf");
var pdf2 = PdfDocument.FromFile("chapter2.pdf");
var pdf3 = PdfDocument.FromFile("chapter3.pdf");
var book = PdfDocument.Merge(pdf1, pdf2, pdf3);
book.SaveAs("complete_book.pdf");
Dim pdf1 = PdfDocument.FromFile("chapter1.pdf")
Dim pdf2 = PdfDocument.FromFile("chapter2.pdf")
Dim pdf3 = PdfDocument.FromFile("chapter3.pdf")
Dim book = PdfDocument.Merge(pdf1, pdf2, pdf3)
book.SaveAs("complete_book.pdf")
ウォーターマーク
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(@"
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>");
pdf.SaveAs("watermarked.pdf");
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(@"
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>");
pdf.SaveAs("watermarked.pdf");
Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.ApplyWatermark("
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>")
pdf.SaveAs("watermarked.pdf")
パスワード保護
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>");
pdf.SecuritySettings.OwnerPassword = "owner123";
pdf.SecuritySettings.UserPassword = "user456";
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SaveAs("protected.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>");
pdf.SecuritySettings.OwnerPassword = "owner123";
pdf.SecuritySettings.UserPassword = "user456";
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SaveAs("protected.pdf");
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>")
pdf.SecuritySettings.OwnerPassword = "owner123"
pdf.SecuritySettings.UserPassword = "user456"
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint
pdf.SaveAs("protected.pdf")
移行チェックリスト
移行前
- すべてのスマトラプロセスの起動を識別します (
Process.Start("SumatraPDF.exe", ...)) - ドキュメント印刷ワークフロー (
-print-to-default引数) - 使用されたSumatraコマンドライン引数をメモします
- IronPDFからIronPDFライセンスキーを取得します
コードの更新
IronPdfNuGetパッケージをインストールします- スマトラプロセスコードを削除
Process.Start("SumatraPDF.exe", pdfPath)をPdfDocument.FromFile(pdfPath)に置き換えます- 外部の
wkhtmltopdf.exe呼び出しをChromePdfRenderer.RenderHtmlAsPdf()に置き換えます - 外部の
pdftotext.exe呼び出しをpdf.ExtractAllText()に置き換えます -print-to-defaultプロセス呼び出しをpdf.Print()に置き換えます- アプリケーションの起動時にライセンスの初期化を追加
テスティング
- PDF生成品質をテストする
- 印刷機能を確認する
- すべてのターゲットプラットフォームでテスト
- スマトラ依存が残っていないことを確認する
クリーンアップ
- インストーラーからSumatraを削除する
- ドキュメントの更新
- システム要件からスマトラを削除する

