
How to generate PDF Files in .NET Core using IronPDF
なぜMuPDFからIronPDFに移行するのか
MuPDFの課題
MuPDF は優れた PDF ツールキットですが、二重 AGPL/商業ライセンス(Artifex 提供)とレンダリング最優先設計が商業的な HTML 主導のアプリケーションを作成する .NET 開発者に現実の摩擦を引き起こします。 2 つの主な .NET ラッパーが存在します:MuPDFCore(コミュニティ、arklumpus による、AGPL-3.0)と MuPDF.NET(Artifex の公式 C# バインディング)
-
**AGPL ライセンスの罠:**MuPDFとラッパーは両方ともデフォルトで AGPL-3.0 の下で出荷されます。 AGPL コードでクローズドソースの製品を配布するには、AGPL の下でオープンソース化するか、Artifex から商用ライセンスを購入する必要があります(価格は公開されておらず見積もりベース)。
-
レンダリング最優先フォーカス: MuPDF.NET は 結合、墨消し、署名、透かしのスタンプを行うことができます(PyMuPDF のミラーリング)、しかしほとんどの API とツールは、HTML 主導のドキュメント生成よりもビューと構造化テキスト抽出に沿って形作られています。
-
HTML-to-PDF エンジンなし: MuPDF.NET も MuPDFCore も HTML/CSS エンジンを搭載していません。HTML から PDF を生成するには、別のブラウザエンジン(Chromium、wkhtmltopdf、PrinceXML)にシェルアウトする必要があり、MuPDF に結果のみをロードします。
-
ネイティブ依存関係: 両方のラッパーは、RIDごとのバイナリ(win-x64、linux-x64、osx-x64)を含む
MuPDFCore.NativeAssets/MuPDF.NativeAssetsパッケージを提供します。 クロスプラットフォームの展開は可能ですが、Docker イメージには一致するネイティブ パッケージとベースイメージ(glibc 対 musl)が必要です。 -
HTML 透かし/ヘッダー/フッターなし: スタンピングはページごとの画像およびテキストベースです; Chromiumベースのレンダラーが提供するような
{page}/{total-pages}テンプレートエンジンはありません。 -
C 相互運用面: ラッパーはコンテキスト/ドキュメントのライフタイムを基底 C ライブラリにマップして公開します - 廃棄順が重要であり、ネイティブクラッシュはプロセス全体をダウンさせる可能性があり、大きなドキュメントに対するマーシャリングコストは非凡です。
MuPDFとIronPDFの比較
| フィーチャー | MuPDF | IronPDF |
|---|---|---|
| ライセンス | AGPL-3.0 または見積もりベースの商業(Artifex) | 商業用(価格を公開) |
| 主な対象 | レンダリング、構造化テキスト、低レベル ツールキット | HTML 主導の生成 + 操作 |
| HTMLからPDFへ | サポートされていません(HTML エンジンなし) | フルChromiumエンジン |
| PDF作成 | ページレベルのみ(テキスト/画像/ベクトルの挿入) | HTML、URL、画像 |
| PDF操作 | MuPDF.NETでサポートされています(DeletePage) | サポートされています(RemovePages) |
| 依存関係 | ネイティブMuPDF+ RID ネイティブ資産 | 管理されたラッパー + バンドルされた Chromium |
| プラットフォームサポート | Win/Linux/macOS でネイティブ資産をご利用いただけます | Win/Linux/macOS/Docker |
| 非同期サポート | ほとんどの同期; MuPDFCore で一部の非同期 | レンダラーとドキュメント全体に渡る非同期 API |
| .NET統合 | C ライブラリを取り囲む P/Invoke ラッパー | .NET ラッパー + ネイティブ Chromium |
IronPDF はネイティブ相互運用の複雑さなしに、モダンな .NET バージョンを通じて管理された .NET ライブラリとして動作します。
マイグレーションの複雑さの評価
機能別の見積もり作業
| フィーチャー | 移行の複雑さ |
|---|---|
| ドキュメントの読み込み | 低レベル |
| テキスト抽出 | 低レベル |
| PDFマージ | 低レベル |
| 画像レンダリング | 低レベル |
| HTMLからPDFへ | 該当なし(新機能) |
| セキュリティ/ウォーターマーク | 該当なし(新機能) |
パラダイムシフト
このMuPDF移行における基本的な変化は、レンダリングのみのビューアから完全な PDF ソリューションへの変化です。
MuPDF.NET: ドキュメント → doc[i] → GetText / GetPixmap / InsertPdf
MuPDFCore: MuPDFContext → MuPDFDocument → Pages[i] → Render / SaveImage
IronPDF: PdfDocument.FromFile() → フル操作 → 作成/編集/結合/セキュリティ
始める前に
前提条件
- .NET環境: .NET Framework 4.6.2+ または.NET Core 3.1+ / .NET 5/6/7/8/9+
- NuGetアクセス: NuGetパッケージをインストールする機能
- IronPDFライセンス: IronPDFからライセンスキーを取得します。
NuGetパッケージの変更
# RemoveMuPDFpackages (whichever wrapper you used)
dotnet remove package MuPDF.NET
dotnet remove package MuPDFCore
dotnet remove package MuPDFCore.NativeAssets.Linux
dotnet remove package MuPDFCore.NativeAssets.MacOS
dotnet remove package MuPDFCore.NativeAssets.Windows
dotnet remove package MuPDF.NativeAssets
# Install IronPDF
dotnet add package IronPdf
また、配置からネイティブMuPDFバイナリを削除してください:
libmupdf.dylibを削除- プラットフォーム固有のフォルダを削除(
runtimes/*/native/) - Dockerファイルを更新してMuPDFのインストールを削除する
ライセンス構成
// 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"' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"MuPDFの使用法を特定する
# Find allMuPDFreferences
grep -r "MuPDF\|MuPDFCore\|MuPDFDocument" --include="*.cs" .
完全な API リファレンス
ドキュメントの読み込み
| MuPDF | IronPDF |
|---|---|
new Document(path)(MuPDF.NET) / new MuPDFDocument(ctx, path)(MuPDFCore) | PdfDocument.FromFile(path) |
new Document("pdf", stream)(MuPDF.NET) | PdfDocument.FromStream(stream) |
doc.Close() / Dispose() | pdf.Dispose() |
ページへのアクセス
| MuPDF | IronPDF |
|---|---|
doc.PageCount(MuPDF.NET) / document.Pages.Count(MuPDFCore) | pdf.PageCount |
doc[index](MuPDF.NET) / document.Pages[index](MuPDFCore) | pdf.Pages[index] |
doc[i].GetText() / 構造化テキストの繰り返し(MuPDFCore) | page.Text |
テキスト抽出
| MuPDF | IronPDF |
|---|---|
doc[i].GetText()をループする | pdf.ExtractAllText() |
PDF作成 (MuPDFでは利用できません)
| MuPDF | IronPDF |
|---|---|
| (HTML エンジンなし) | ChromePdfRenderer.RenderHtmlAsPdf(html) |
| (HTML エンジンなし) | ChromePdfRenderer.RenderUrlAsPdf(url) |
PDF操作
| MuPDF | IronPDF |
|---|---|
docA.InsertPdf(docB)(MuPDF.NET) | PdfDocument.Merge(pdf1, pdf2) |
1ページあたりpage.InsertImage(...)(画像/テキストスタンプのみ) | pdf.ApplyWatermark(html) |
doc.Save(path, encryption: ..., ownerPw: ..., userPw: ...) | pdf.SecuritySettings |
コード移行の例
例 1: HTML から PDF への変換 (MuPDF ではできません)
翻訳前 (MuPDF):
// NuGet: Install-Package MuPDF.NET
using MuPDFCore;
using System.IO;
class Program
{
static void Main()
{
//MuPDFdoesn't supportHTMLからPDFへconversion directly
// You would need to use another library to convert HTML to a supported format first
// This is a limitation -MuPDFis primarily a PDF renderer/viewer
// Alternative: Use a browser engine or intermediate conversion
string html = "<html><body><h1>Hello World</h1></body></html>";
// Not natively supported in MuPDF
throw new NotSupportedException("MuPDF does not support directHTMLからPDFへconversion");
}
}// NuGet: Install-Package MuPDF.NET
using MuPDFCore;
using System.IO;
class Program
{
static void Main()
{
//MuPDFdoesn't supportHTMLからPDFへconversion directly
// You would need to use another library to convert HTML to a supported format first
// This is a limitation -MuPDFis primarily a PDF renderer/viewer
// Alternative: Use a browser engine or intermediate conversion
string html = "<html><body><h1>Hello World</h1></body></html>";
// Not natively supported in MuPDF
throw new NotSupportedException("MuPDF does not support directHTMLからPDFへconversion");
}
}' NuGet: Install-Package MuPDF.NET
Imports MuPDFCore
Imports System.IO
Class Program
Shared Sub Main()
' MuPDFdoesn't supportHTMLからPDFへconversion directly
' You would need to use another library to convert HTML to a supported format first
' This is a limitation -MuPDFis primarily a PDF renderer/viewer
' Alternative: Use a browser engine or intermediate conversion
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
' Not natively supported in MuPDF
Throw New NotSupportedException("MuPDF does not support directHTMLからPDFへconversion")
End Sub
End Class' NuGet: Install-Package MuPDF.NET
Imports MuPDFCore
Imports System.IO
Class Program
Shared Sub Main()
' MuPDFdoesn't supportHTMLからPDFへconversion directly
' You would need to use another library to convert HTML to a supported format first
' This is a limitation -MuPDFis primarily a PDF renderer/viewer
' Alternative: Use a browser engine or intermediate conversion
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
' Not natively supported in MuPDF
Throw New NotSupportedException("MuPDF does not support directHTMLからPDFへconversion")
End Sub
End Class翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Class' NuGet: Install-Package IronPdf
Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Classこの例では、MuPDFの最も重要な制限である、HTMLをPDFにまったく変換できないことを強調しています。 MuPDFのコードはNotSupportedExceptionを明示的にスローします。HTMLからPDFへの変換はMuPDFでは提供されていない機能だからです。 MuPDFでこの機能が必要な場合、wkhtmltopdfのような別のライブラリやブラウザエンジンを使用し、その後MuPDFで結果のPDFを読み込んで表示する必要がありました。
IronPDFのChromePdfRendererは、完全なCSS3、JavaScript、および最新のWeb標準をサポートしてHTMLをレンダリングするための完全なChromiumエンジンを使用します。 RenderHtmlAsPdf()メソッドはHTML文字列を直接受け入れます。 URLレンダリングやHTMLファイル変換を含むその他のレンダリングオプションについては、HTML to PDF documentationを参照してください。
例2: テキスト抽出
翻訳前 (MuPDF):
// NuGet: Install-Package MuPDF.NET
using MuPDF.NET;
using System;
using System.Text;
class Program
{
static void Main()
{
Document doc = new Document("input.pdf");
StringBuilder allText = new StringBuilder();
for (int i = 0; i < doc.PageCount; i++)
{
string pageText = doc[i].GetText();
allText.AppendLine(pageText);
}
Console.WriteLine(allText.ToString());
}
}// NuGet: Install-Package MuPDF.NET
using MuPDF.NET;
using System;
using System.Text;
class Program
{
static void Main()
{
Document doc = new Document("input.pdf");
StringBuilder allText = new StringBuilder();
for (int i = 0; i < doc.PageCount; i++)
{
string pageText = doc[i].GetText();
allText.AppendLine(pageText);
}
Console.WriteLine(allText.ToString());
}
}Imports MuPDF.NET
Imports System
Imports System.Text
Module Program
Sub Main()
Dim doc As New Document("input.pdf")
Dim allText As New StringBuilder()
For i As Integer = 0 To doc.PageCount - 1
Dim pageText As String = doc(i).GetText()
allText.AppendLine(pageText)
Next
Console.WriteLine(allText.ToString())
End Sub
End ModuleImports MuPDF.NET
Imports System
Imports System.Text
Module Program
Sub Main()
Dim doc As New Document("input.pdf")
Dim allText As New StringBuilder()
For i As Integer = 0 To doc.PageCount - 1
Dim pageText As String = doc(i).GetText()
allText.AppendLine(pageText)
Next
Console.WriteLine(allText.ToString())
End Sub
End Module翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
string text = pdf.ExtractAllText();
Console.WriteLine(text);
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
string text = pdf.ExtractAllText();
Console.WriteLine(text);
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System
Module Program
Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
Dim text As String = pdf.ExtractAllText()
Console.WriteLine(text)
End Sub
End Module' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System
Module Program
Sub Main()
Dim pdf = PdfDocument.FromFile("input.pdf")
Dim text As String = pdf.ExtractAllText()
Console.WriteLine(text)
End Sub
End ModuleMuPDF.NETのアプローチは、StringBuilderを使用してテキストを構築します。
IronPDFではこれを3行に減らします。ドキュメントはExtractAllText()を呼び出し、結果を印刷します。 手動での繰り返しも、StringBuilderも不要です。 PDF からのテキスト抽出について詳しく学びます。
例3: 複数のPDFをマージする
翻訳前 (MuPDF):
// NuGet: Install-Package MuPDF.NET
using MuPDF.NET;
class Program
{
static void Main()
{
Document doc1 = new Document("file1.pdf");
Document doc2 = new Document("file2.pdf");
// Append every page of doc2 to the end of doc1.
doc1.InsertPdf(doc2);
doc1.Save("merged.pdf");
}
}// NuGet: Install-Package MuPDF.NET
using MuPDF.NET;
class Program
{
static void Main()
{
Document doc1 = new Document("file1.pdf");
Document doc2 = new Document("file2.pdf");
// Append every page of doc2 to the end of doc1.
doc1.InsertPdf(doc2);
doc1.Save("merged.pdf");
}
}Imports MuPDF.NET
Class Program
Shared Sub Main()
Dim doc1 As New Document("file1.pdf")
Dim doc2 As New Document("file2.pdf")
' Append every page of doc2 to the end of doc1.
doc1.InsertPdf(doc2)
doc1.Save("merged.pdf")
End Sub
End ClassImports MuPDF.NET
Class Program
Shared Sub Main()
Dim doc1 As New Document("file1.pdf")
Dim doc2 As New Document("file2.pdf")
' Append every page of doc2 to the end of doc1.
doc1.InsertPdf(doc2)
doc1.Save("merged.pdf")
End Sub
End Class翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("file1.pdf");
var pdf2 = PdfDocument.FromFile("file2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("file1.pdf");
var pdf2 = PdfDocument.FromFile("file2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("file1.pdf")
Dim pdf2 = PdfDocument.FromFile("file2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End Class' NuGet: Install-Package IronPdf
Imports IronPdf
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("file1.pdf")
Dim pdf2 = PdfDocument.FromFile("file2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End ClassMuPDF.NETはinsert_pdf()を反映し、1つのドキュメントのすべてのページを別のドキュメントに上書きされた形で追加します。 MuPDFCoreは同等の高レベルなマージAPIを公開していません。
IronPDFの静的PdfDocument.Merge()メソッドは、複数のPDFドキュメントを受け取り、入力には手を触れずに単一のマージされたドキュメントを返します。 多くのドキュメントをマージするには、リストを渡します:PdfDocument.Merge(pdfList)。 その他のオプションについては、PDFのマージと分割のドキュメントを参照してください。
重要な移行に関する注意事項
ネイティブ バイナリの削除
MuPDFにはプラットフォーム固有のネイティブライブラリが必要です。 IronPDFに移行した後、すべてのMuPDFネイティブバイナリを削除してください:
# Delete native libraries
rm -f mupdf*.dll libmupdf*.so libmupdf*.dylib
# Remove runtime folders
rm -rf runtimes/*/native/
# Update Docker files to removeMuPDFinstallation
IronPDFは完全に管理された.NETコードです。プラットフォーム間で管理するネイティブバイナリはありません。
簡略化された Dispose パターン
MuPDFCoreでは明確なMuPDFContextが必要です。 MuPDF.NETはそれを隠しますが、Close() / Dispose()がまだ必要です:
// MuPDFCore: explicit context required
using (var context = new MuPDFContext())
using (var document = new MuPDFDocument(context, "input.pdf"))
{
// Work with document
}
// MuPDF.NET: implicit context, manual close
Document doc = new Document("input.pdf");
try { /* work */ } finally { doc.Close(); }
// IronPDF: simpler pattern
var pdf = PdfDocument.FromFile("input.pdf");
// Work with pdf// MuPDFCore: explicit context required
using (var context = new MuPDFContext())
using (var document = new MuPDFDocument(context, "input.pdf"))
{
// Work with document
}
// MuPDF.NET: implicit context, manual close
Document doc = new Document("input.pdf");
try { /* work */ } finally { doc.Close(); }
// IronPDF: simpler pattern
var pdf = PdfDocument.FromFile("input.pdf");
// Work with pdfImports MuPDFCore
Imports MuPDF.NET
Imports IronPDF
' MuPDFCore: explicit context required
Using context As New MuPDFContext()
Using document As New MuPDFDocument(context, "input.pdf")
' Work with document
End Using
End Using
' MuPDF.NET: implicit context, manual close
Dim doc As New Document("input.pdf")
Try
' work
Finally
doc.Close()
End Try
' IronPDF: simpler pattern
Dim pdf = PdfDocument.FromFile("input.pdf")
' Work with pdfImports MuPDFCore
Imports MuPDF.NET
Imports IronPDF
' MuPDFCore: explicit context required
Using context As New MuPDFContext()
Using document As New MuPDFDocument(context, "input.pdf")
' Work with document
End Using
End Using
' MuPDF.NET: implicit context, manual close
Dim doc As New Document("input.pdf")
Try
' work
Finally
doc.Close()
End Try
' IronPDF: simpler pattern
Dim pdf = PdfDocument.FromFile("input.pdf")
' Work with pdfページの反復パターンの変更
MuPDFは、ページ数を明示したインデックスベースの反復を使用します:
// MuPDF.NET
for (int i = 0; i < doc.PageCount; i++)
{
var pageText = doc[i].GetText();
}
// MuPDFCore
for (int i = 0; i < document.Pages.Count; i++)
{
var pageText = document.Pages[i].GetText();
}
//IronPDF(foreach supported)
foreach (var page in pdf.Pages)
{
var pageText = page.Text;
}// MuPDF.NET
for (int i = 0; i < doc.PageCount; i++)
{
var pageText = doc[i].GetText();
}
// MuPDFCore
for (int i = 0; i < document.Pages.Count; i++)
{
var pageText = document.Pages[i].GetText();
}
//IronPDF(foreach supported)
foreach (var page in pdf.Pages)
{
var pageText = page.Text;
}' MuPDF.NET
For i As Integer = 0 To doc.PageCount - 1
Dim pageText = doc(i).GetText()
Next
' MuPDFCore
For i As Integer = 0 To document.Pages.Count - 1
Dim pageText = document.Pages(i).GetText()
Next
' IronPDF(foreach supported)
For Each page In pdf.Pages
Dim pageText = page.Text
Next' MuPDF.NET
For i As Integer = 0 To doc.PageCount - 1
Dim pageText = doc(i).GetText()
Next
' MuPDFCore
For i As Integer = 0 To document.Pages.Count - 1
Dim pageText = document.Pages(i).GetText()
Next
' IronPDF(foreach supported)
For Each page In pdf.Pages
Dim pageText = page.Text
Next新しい機能が利用可能です
IronPDFに移行した後は、MuPDFでは提供できない機能を得ることができます:
//PDF作成from HTML (not possible in MuPDF)
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello</h1>");
// Watermarks (not possible in MuPDF)
pdf.ApplyWatermark("<div style='color:red;opacity:0.3;'>DRAFT</div>");
// Password Protection (not possible in MuPDF)
pdf.SecuritySettings.OwnerPassword = "admin";
pdf.SecuritySettings.UserPassword = "user";
// Headers and Footers (no HTML header/footer template in MuPDF)
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center;'>Document Title</div>",
MaxHeight = 25
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center;'>Page {page} of {total-pages}</div>",
MaxHeight = 25
};//PDF作成from HTML (not possible in MuPDF)
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello</h1>");
// Watermarks (not possible in MuPDF)
pdf.ApplyWatermark("<div style='color:red;opacity:0.3;'>DRAFT</div>");
// Password Protection (not possible in MuPDF)
pdf.SecuritySettings.OwnerPassword = "admin";
pdf.SecuritySettings.UserPassword = "user";
// Headers and Footers (no HTML header/footer template in MuPDF)
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center;'>Document Title</div>",
MaxHeight = 25
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = "<div style='text-align:center;'>Page {page} of {total-pages}</div>",
MaxHeight = 25
};' PDF作成from HTML (not possible in MuPDF)
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello</h1>")
' Watermarks (not possible in MuPDF)
pdf.ApplyWatermark("<div style='color:red;opacity:0.3;'>DRAFT</div>")
' Password Protection (not possible in MuPDF)
pdf.SecuritySettings.OwnerPassword = "admin"
pdf.SecuritySettings.UserPassword = "user"
' Headers and Footers (no HTML header/footer template in MuPDF)
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
.HtmlFragment = "<div style='text-align:center;'>Document Title</div>",
.MaxHeight = 25
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
.HtmlFragment = "<div style='text-align:center;'>Page {page} of {total-pages}</div>",
.MaxHeight = 25
}' PDF作成from HTML (not possible in MuPDF)
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello</h1>")
' Watermarks (not possible in MuPDF)
pdf.ApplyWatermark("<div style='color:red;opacity:0.3;'>DRAFT</div>")
' Password Protection (not possible in MuPDF)
pdf.SecuritySettings.OwnerPassword = "admin"
pdf.SecuritySettings.UserPassword = "user"
' Headers and Footers (no HTML header/footer template in MuPDF)
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
.HtmlFragment = "<div style='text-align:center;'>Document Title</div>",
.MaxHeight = 25
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
.HtmlFragment = "<div style='text-align:center;'>Page {page} of {total-pages}</div>",
.MaxHeight = 25
}トラブルシューティング
問題 1: MuPDFDocument が見つかりません
問題: IronPDFにはMuPDFDocumentクラスが存在しません。
解決策: PdfDocument.FromFile()を使用します:
// MuPDF
using (MuPDFDocument document = new MuPDFDocument("input.pdf"))
// IronPDF
var pdf = PdfDocument.FromFile("input.pdf");// MuPDF
using (MuPDFDocument document = new MuPDFDocument("input.pdf"))
// IronPDF
var pdf = PdfDocument.FromFile("input.pdf");Imports MuPDF
Imports IronPDF
Using document As New MuPDFDocument("input.pdf")
End Using
Dim pdf = PdfDocument.FromFile("input.pdf")Imports MuPDF
Imports IronPDF
Using document As New MuPDFDocument("input.pdf")
End Using
Dim pdf = PdfDocument.FromFile("input.pdf")課題2:Pages.Countが見つかりません
問題: document.Pages.Countパターンが機能しません。
解決策: pdf.PageCountを使用します:
// MuPDF
for (int i = 0; i < document.Pages.Count; i++)
// IronPDF
for (int i = 0; i < pdf.PageCount; i++)
// Or use: foreach (var page in pdf.Pages)// MuPDF
for (int i = 0; i < document.Pages.Count; i++)
// IronPDF
for (int i = 0; i < pdf.PageCount; i++)
// Or use: foreach (var page in pdf.Pages)' MuPDF
For i As Integer = 0 To document.Pages.Count - 1
' IronPDF
For i As Integer = 0 To pdf.PageCount - 1
' Or use: For Each page In pdf.Pages' MuPDF
For i As Integer = 0 To document.Pages.Count - 1
' IronPDF
For i As Integer = 0 To pdf.PageCount - 1
' Or use: For Each page In pdf.Pages問題 3: GetText() が見つかりません
問題: page.GetText()メソッドは存在しません。
解決策: pdf.ExtractAllText()を使用します:
// MuPDF
string pageText = document.Pages[i].GetText();
// IronPDF
string pageText = pdf.Pages[i].Text;
// Or for all text:
string allText = pdf.ExtractAllText();// MuPDF
string pageText = document.Pages[i].GetText();
// IronPDF
string pageText = pdf.Pages[i].Text;
// Or for all text:
string allText = pdf.ExtractAllText();' MuPDF
Dim pageText As String = document.Pages(i).GetText()
' IronPDF
Dim pageText As String = pdf.Pages(i).Text
' Or for all text:
Dim allText As String = pdf.ExtractAllText()' MuPDF
Dim pageText As String = document.Pages(i).GetText()
' IronPDF
Dim pageText As String = pdf.Pages(i).Text
' Or for all text:
Dim allText As String = pdf.ExtractAllText()問題4: InsertPdfが見つかりません
問題: MuPDF.NETのinsert_pdfを反映)は、IronPDFには直接の同等の名前がなく、MuPDFCoreは高レベルのマージをまったく公開していません。
解決策: 静的PdfDocument.Merge()を使用します:
// MuPDF.NET
docA.InsertPdf(docB);
// IronPDF
var merged = PdfDocument.Merge(pdf1, pdf2);// MuPDF.NET
docA.InsertPdf(docB);
// IronPDF
var merged = PdfDocument.Merge(pdf1, pdf2);netnet移行チェックリスト
移行前
- コードベース内のすべてのMuPDFの使用状況をインベントリする
- すべてのレンダリング操作(DPI、スケール係数)を文書化する
- PDF 作成のニーズを特定する (現在は外部ツールを使用)
- テキスト抽出要件をリストする
- ネイティブバイナリ処理のデプロイメントスクリプトを確認する
- IronPDFライセンスキーを取得する
パッケージの変更
MuPDF.NETパッケージを削除MuPDFCoreパッケージを削除MuPDFCore.NativeAssets.*/MuPDF.NativeAssetsパッケージを削除IronPdfNuGetパッケージをインストール:dotnet add package IronPdf- 名前空間のインポートを更新する
コードの変更
- 起動時にライセンスキー設定を追加する
Document(MuPDF.NET) /MuPDFDocument(MuPDFCore)を置き換えるdoc.PageCount/pdf.PageCountに置き換えるpdf.ExtractAllText()に置き換えるPdfDocument.Merge()に置き換える- 明示的なコンテキスト/破棄ボイラープレートを削除します
- 必要に応じて PDF 作成コードを追加します (HTML から PDF)
移行後
- プロジェクトからネイティブMuPDFバイナリを削除する
- Dockerファイルを更新してMuPDFのインストールを削除する
- プラットフォーム固有のランタイムフォルダを削除する
- レンダリングされた出力を比較する回帰テストを実行する
- すべてのターゲットプラットフォーム(Windows、Linux、macOS)でテスト
- 新しい機能(透かし、セキュリティ、ヘッダー/フッター)の追加を検討する
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
関連する記事


