
How to View PDFs in C# NET MAUI App | IronPDF
XFINIUM.PDFは、O2 Solutionsによって開発された商用クロスプラットフォームPDFライブラリで、C#でPDFをプログラム的に作成および編集するためのツールを提供します。 2つのエディションがあります – ジェネレーター(PDF生成と編集)とビューアー(ジェネレーターの機能に加えてレンダリング/表示)。 ライブラリはNuGetでXfinium.Pdf.NetCoreとして配布されています。 座標に基づいたグラフィックスプログラミングモデルは、ドキュメントが多いアプリケーションを構築するチームに摩擦を生じさせる可能性があります。ほとんどのレイアウトの作業は、ピクセル座標を使用して要素を手動で位置決めすることを伴うからです。
このガイドは、XFINIUM.PDFからIronPDFへの移行経路を提供し、.NET開発者がこの移行を評価するためのステップバイステップの指示、コードの比較、および実用的な例を提供します。
なぜXFINIUM.PDFから移行するのか
XFINIUM.PDFは、開発者がページ上のほとんどの要素を直接位置付けることを意味する座標ベースのグラフィックスプログラミングに依存する低レベルのPDFライブラリです。 開発チームが移行を検討する一般的な理由には以下が含まれます:
ネイティブHTMLエンジンなし: XFINIUM.PDFには組み込みのHTML-to-PDFコンバーターがありません。 ベンダーは制限されたタグセットをサポートするサンプルXHTMLウォーカーを提供していますが、CSSの解析やJavaScriptの実行は行わないため、完全なHTML-to-PDF機能が必要なプロジェクトには不十分な場合があります。
座標ベースのAPI: ほとんどの要素配置にはDrawString("text", font, brush, 50, 100)のようなピクセル座標での手動位置設定が必要です。
フォント管理の手動設定: フォントオブジェクトはPdfBrushのようなクラスを利用して明示的に作成および管理する必要があります。
CSS スタイルなし:最新の Web スタイルはサポートされていません。 色、フォント、およびレイアウトはプログラムメソッド呼び出しを通じて処理されます。
JavaScriptレンダリングなし:静的コンテンツのみ。 XFINIUM.PDFは動的なウェブコンテンツをレンダリングしたりJavaScriptを実行したりしません。
複雑なテキストレイアウト: 簡単な単一行テキストを超えるものには通常手動のテキスト測定と折り返し計算が必要です。
小さいコミュニティ: 主流のソリューションと比べてコミュニティ提供の例やチュートリアルが少ないため、新規ユーザーの始まりが難しくなる可能性があります。
核心的な問題: グラフィックス API 対 HTML
XFINIUM.PDFは、ドキュメントデザイナーではなく、グラフィックプログラマーのように考えることを強制します:
// XFINIUM.PDF: Position every element manually
page.Graphics.DrawString("Invoice", titleFont, titleBrush, 50, 50);
page.Graphics.DrawString("Customer:", labelFont, brush, 50, 80);
page.Graphics.DrawString(customer.Name, valueFont, brush, 120, 80);
// ... hundreds of lines for a simple document' XFINIUM.PDF: Position every element manually
page.Graphics.DrawString("Invoice", titleFont, titleBrush, 50, 50)
page.Graphics.DrawString("Customer:", labelFont, brush, 50, 80)
page.Graphics.DrawString(customer.Name, valueFont, brush, 120, 80)
' ... hundreds of lines for a simple document' XFINIUM.PDF: Position every element manually
page.Graphics.DrawString("Invoice", titleFont, titleBrush, 50, 50)
page.Graphics.DrawString("Customer:", labelFont, brush, 50, 80)
page.Graphics.DrawString(customer.Name, valueFont, brush, 120, 80)
' ... hundreds of lines for a simple documentIronPDFは使い慣れたHTML/CSSを使用しています:
// IronPDF: Declarative HTML
var html = @"<h1>Invoice</h1><p><b>Customer:</b> " + customer.Name + "</p>";
var pdf = renderer.RenderHtmlAsPdf(html);// IronPDF: Declarative HTML
var html = @"<h1>Invoice</h1><p><b>Customer:</b> " + customer.Name + "</p>";
var pdf = renderer.RenderHtmlAsPdf(html);' IronPDF: Declarative HTML
Dim html As String = "<h1>Invoice</h1><p><b>Customer:</b> " & customer.Name & "</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)' IronPDF: Declarative HTML
Dim html As String = "<h1>Invoice</h1><p><b>Customer:</b> " & customer.Name & "</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)IronPDFとXFINIUM.PDFの比較:機能比較
アーキテクチャの違いを理解することは、技術的な意思決定者が移行への投資を評価するのに役立ちます:
| フィーチャー | XFINIUM.PDF | IronPDF |
|---|---|---|
| HTMLからPDFへ | ネイティブエンジンなし; サンプル専用のXHTMLコンバーター(限られたタグ、CSS/JSなし) | Chromium(CSS3 + JavaScript)を使用した完全なHTML-to-PDF変換 |
| コミュニティ&サポート | コミュニティが小さく、利用可能なオンラインリソースが少ない | 広範なドキュメントとチュートリアルを備えた大規模コミュニティ |
| ライセンス | 開発者ベースの商用ライセンス | 商用 |
| クロスプラットフォーム・サポート | 強力なクロスプラットフォーム機能 | クロスプラットフォームにも対応 |
| CSSサポート | なし | 完全なCSS3 |
| JavaScript(JavaScript | なし | フルES2024 |
| フレックスボックス/グリッド | なし | はい |
| 自動レイアウト。 | なし | はい |
| 自動改ページ | なし | はい |
| マニュアルポジショニング | 必須 | オプション(CSSポジショニング) |
| ラーニングカーブ | 高(座標系) | 低レベル(HTML/CSS) |
| コードの正確さ | 非常に高い | 低レベル |
クイックスタート:XFINIUM.PDFからIronPDFへの移行
これらの基本的なステップを踏めば、すぐにでも移行を開始できます。
ステップ 1: NuGet パッケージを置き換える
XFINIUM.PDFを削除します(実際のNuGet IDはプラットフォーム固有です)。
# Remove XFINIUM.PDF
dotnet remove package Xfinium.Pdf.NetStandard
# or: dotnet remove package Xfinium.Pdf.NetCore
IronPDFをインストールします:
# Install IronPDF
dotnet add package IronPdf
ステップ 2: 名前空間の更新
XFINIUM.PDFの名前空間をIronPDFの名前空間に置き換えます:
// Before (XFINIUM.PDF)
using Xfinium.Pdf;
using Xfinium.Pdf.Graphics;
using Xfinium.Pdf.Content;
using Xfinium.Pdf.FlowDocument;
// After (IronPDF)
using IronPdf;// Before (XFINIUM.PDF)
using Xfinium.Pdf;
using Xfinium.Pdf.Graphics;
using Xfinium.Pdf.Content;
using Xfinium.Pdf.FlowDocument;
// After (IronPDF)
using IronPdf;Imports IronPdfImports IronPdfステップ 3: ライセンスの初期化
アプリケーション起動時のライセンス初期化を追加します:
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"コード移行の例
HTML を PDF に変換する
最も基本的な操作は、これら for .NET PDFライブラリの複雑さの違いを明らかにします。
**XFINIUM.PDFのアプローチ: **
// NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
// XFINIUM.PDF has no native HTML-to-PDF engine. Flow content accepts
// styled text, headings, tables and images - not HTML. The vendor sample
// converter parses limited XHTML (p, font, b, i, u, ul, li) into
// PdfFormattedContent; full CSS/JS rendering is not supported.
using Xfinium.Pdf;
using Xfinium.Pdf.FlowDocument;
using Xfinium.Pdf.Graphics;
using System.IO;
class Program
{
static void Main()
{
PdfFlowDocument flowDocument = new PdfFlowDocument();
flowDocument.AddContent(new PdfFlowHeadingContent(
"Hello World",
new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18)));
flowDocument.AddContent(new PdfFlowTextContent(
"This is a PDF generated from text content (not HTML).",
new PdfStandardFont(PdfStandardFontFace.Helvetica, 12)));
using (FileStream fs = new FileStream("output.pdf", FileMode.Create))
{
flowDocument.Save(fs);
}
}
}// NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
// XFINIUM.PDF has no native HTML-to-PDF engine. Flow content accepts
// styled text, headings, tables and images - not HTML. The vendor sample
// converter parses limited XHTML (p, font, b, i, u, ul, li) into
// PdfFormattedContent; full CSS/JS rendering is not supported.
using Xfinium.Pdf;
using Xfinium.Pdf.FlowDocument;
using Xfinium.Pdf.Graphics;
using System.IO;
class Program
{
static void Main()
{
PdfFlowDocument flowDocument = new PdfFlowDocument();
flowDocument.AddContent(new PdfFlowHeadingContent(
"Hello World",
new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18)));
flowDocument.AddContent(new PdfFlowTextContent(
"This is a PDF generated from text content (not HTML).",
new PdfStandardFont(PdfStandardFontFace.Helvetica, 12)));
using (FileStream fs = new FileStream("output.pdf", FileMode.Create))
{
flowDocument.Save(fs);
}
}
}Imports Xfinium.Pdf
Imports Xfinium.Pdf.FlowDocument
Imports Xfinium.Pdf.Graphics
Imports System.IO
Module Program
Sub Main()
Dim flowDocument As New PdfFlowDocument()
flowDocument.AddContent(New PdfFlowHeadingContent(
"Hello World",
New PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18)))
flowDocument.AddContent(New PdfFlowTextContent(
"This is a PDF generated from text content (not HTML).",
New PdfStandardFont(PdfStandardFontFace.Helvetica, 12)))
Using fs As New FileStream("output.pdf", FileMode.Create)
flowDocument.Save(fs)
End Using
End Sub
End ModuleImports Xfinium.Pdf
Imports Xfinium.Pdf.FlowDocument
Imports Xfinium.Pdf.Graphics
Imports System.IO
Module Program
Sub Main()
Dim flowDocument As New PdfFlowDocument()
flowDocument.AddContent(New PdfFlowHeadingContent(
"Hello World",
New PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18)))
flowDocument.AddContent(New PdfFlowTextContent(
"This is a PDF generated from text content (not HTML).",
New PdfStandardFont(PdfStandardFontFace.Helvetica, 12)))
Using fs As New FileStream("output.pdf", FileMode.Create)
flowDocument.Save(fs)
End Using
End Sub
End ModuleIronPDFのアプローチ:
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></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><p>This is a PDF from HTML.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Module Program
Sub Main()
Dim renderer As New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Module' NuGet: Install-Package IronPdf
Imports IronPdf
Module Program
Sub Main()
Dim renderer As New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF from HTML.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End ModuleXFINIUM.PDFでは、FileStreamを使って保存します。 フロードキュメントAPIはHTMLマークアップではなく型付きコンテンツオブジェクトを受け入れます。IronPDFはこれを3行で簡素化します: レンダラーを作成し、HTMLをレンダリングし、保存します。
高度なHTMLからPDFへのシナリオについては、HTMLからPDFへの変換ガイドをご覧ください。
複数のPDFをマージする
PDFマージは、APIの複雑さの違いを明確に示します。
**XFINIUM.PDFのアプローチ: **
// NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
using Xfinium.Pdf;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument output = new PdfFixedDocument();
FileStream file1 = File.OpenRead("document1.pdf");
PdfFixedDocument pdf1 = new PdfFixedDocument(file1);
FileStream file2 = File.OpenRead("document2.pdf");
PdfFixedDocument pdf2 = new PdfFixedDocument(file2);
for (int i = 0; i < pdf1.Pages.Count; i++)
{
output.Pages.Add(pdf1.Pages[i]);
}
for (int i = 0; i < pdf2.Pages.Count; i++)
{
output.Pages.Add(pdf2.Pages[i]);
}
output.Save("merged.pdf");
file1.Close();
file2.Close();
}
}// NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
using Xfinium.Pdf;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument output = new PdfFixedDocument();
FileStream file1 = File.OpenRead("document1.pdf");
PdfFixedDocument pdf1 = new PdfFixedDocument(file1);
FileStream file2 = File.OpenRead("document2.pdf");
PdfFixedDocument pdf2 = new PdfFixedDocument(file2);
for (int i = 0; i < pdf1.Pages.Count; i++)
{
output.Pages.Add(pdf1.Pages[i]);
}
for (int i = 0; i < pdf2.Pages.Count; i++)
{
output.Pages.Add(pdf2.Pages[i]);
}
output.Save("merged.pdf");
file1.Close();
file2.Close();
}
}' NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
Imports Xfinium.Pdf
Imports System.IO
Class Program
Shared Sub Main()
Dim output As New PdfFixedDocument()
Dim file1 As FileStream = File.OpenRead("document1.pdf")
Dim pdf1 As New PdfFixedDocument(file1)
Dim file2 As FileStream = File.OpenRead("document2.pdf")
Dim pdf2 As New PdfFixedDocument(file2)
For i As Integer = 0 To pdf1.Pages.Count - 1
output.Pages.Add(pdf1.Pages(i))
Next
For i As Integer = 0 To pdf2.Pages.Count - 1
output.Pages.Add(pdf2.Pages(i))
Next
output.Save("merged.pdf")
file1.Close()
file2.Close()
End Sub
End Class' NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
Imports Xfinium.Pdf
Imports System.IO
Class Program
Shared Sub Main()
Dim output As New PdfFixedDocument()
Dim file1 As FileStream = File.OpenRead("document1.pdf")
Dim pdf1 As New PdfFixedDocument(file1)
Dim file2 As FileStream = File.OpenRead("document2.pdf")
Dim pdf2 As New PdfFixedDocument(file2)
For i As Integer = 0 To pdf1.Pages.Count - 1
output.Pages.Add(pdf1.Pages(i))
Next
For i As Integer = 0 To pdf2.Pages.Count - 1
output.Pages.Add(pdf2.Pages(i))
Next
output.Save("merged.pdf")
file1.Close()
file2.Close()
End Sub
End ClassIronPDFのアプローチ:
// NuGet: Install-Package IronPdf
using IronPdf;
using System.Collections.Generic;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System.Collections.Generic;
class Program
{
static void Main()
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End Class' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End ClassXFINIUM.PDFは、出力文書を作成し、ファイルストリームを開き、各文書を読み込み、手動でページを繰り返し、1つずつ追加し、保存し、ストリームを閉じる必要があります。 IronPDFはすべての複雑さを内部で処理する単一のPdfDocument.Merge()メソッドを提供します。
その他のマージ オプションについては、PDF マージ ドキュメントを参照してください。
テキストと画像でPDFを作成する
内容が混在する文書は、基本的なパラダイムの違いを示しています。
**XFINIUM.PDFのアプローチ: **
// NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
using Xfinium.Pdf;
using Xfinium.Pdf.Graphics;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
PdfStandardFont font = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
PdfBrush brush = new PdfBrush(new PdfRgbColor(0, 0, 0));
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50);
using (FileStream imageStream = File.OpenRead("image.jpg"))
{
PdfJpegImage image = new PdfJpegImage(imageStream);
page.Graphics.DrawImage(image, 50, 100, 200, 150);
}
document.Save("output.pdf");
}
}// NuGet: Install-Package Xfinium.Pdf.NetStandard (or .NetCore)
using Xfinium.Pdf;
using Xfinium.Pdf.Graphics;
using System.IO;
class Program
{
static void Main()
{
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
PdfStandardFont font = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
PdfBrush brush = new PdfBrush(new PdfRgbColor(0, 0, 0));
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50);
using (FileStream imageStream = File.OpenRead("image.jpg"))
{
PdfJpegImage image = new PdfJpegImage(imageStream);
page.Graphics.DrawImage(image, 50, 100, 200, 150);
}
document.Save("output.pdf");
}
}Imports Xfinium.Pdf
Imports Xfinium.Pdf.Graphics
Imports System.IO
Class Program
Shared Sub Main()
Dim document As New PdfFixedDocument()
Dim page As PdfPage = document.Pages.Add()
Dim font As New PdfStandardFont(PdfStandardFontFace.Helvetica, 24)
Dim brush As New PdfBrush(New PdfRgbColor(0, 0, 0))
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50)
Using imageStream As FileStream = File.OpenRead("image.jpg")
Dim image As New PdfJpegImage(imageStream)
page.Graphics.DrawImage(image, 50, 100, 200, 150)
End Using
document.Save("output.pdf")
End Sub
End ClassImports Xfinium.Pdf
Imports Xfinium.Pdf.Graphics
Imports System.IO
Class Program
Shared Sub Main()
Dim document As New PdfFixedDocument()
Dim page As PdfPage = document.Pages.Add()
Dim font As New PdfStandardFont(PdfStandardFontFace.Helvetica, 24)
Dim brush As New PdfBrush(New PdfRgbColor(0, 0, 0))
page.Graphics.DrawString("Sample PDF Document", font, brush, 50, 50)
Using imageStream As FileStream = File.OpenRead("image.jpg")
Dim image As New PdfJpegImage(imageStream)
page.Graphics.DrawImage(image, 50, 100, 200, 150)
End Using
document.Save("output.pdf")
End Sub
End ClassIronPDFのアプローチ:
// NuGet: Install-Package IronPdf
using IronPdf;
using System.IO;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string imageBase64 = Convert.ToBase64String(File.ReadAllBytes("image.jpg"));
string html = $@"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System.IO;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string imageBase64 = Convert.ToBase64String(File.ReadAllBytes("image.jpg"));
string html = $@"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System.IO
Module Program
Sub Main()
Dim renderer As New ChromePdfRenderer()
Dim imageBase64 As String = Convert.ToBase64String(File.ReadAllBytes("image.jpg"))
Dim html As String = $"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Module' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System.IO
Module Program
Sub Main()
Dim renderer As New ChromePdfRenderer()
Dim imageBase64 As String = Convert.ToBase64String(File.ReadAllBytes("image.jpg"))
Dim html As String = $"
<html>
<body>
<h1>Sample PDF Document</h1>
<img src='data:image/jpeg;base64,{imageBase64}' width='200' height='150' />
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End ModuleXFINIUM.PDFでは、ドキュメントの作成、ページの追加、フォントおよびブラシオブジェクトの作成、特定の座標にテキストを描画、画像ストリームのオープン、PdfJpegImageの作成、座標にサイズで画像を描画、ストリームのクローズ、保存といった作業が必要です。 IronPDFはbase64画像を埋め込んだ標準的なHTMLを使用しています。
XFINIUM.PDFAPIからIronPDFへのマッピングリファレンス
このマッピングは、APIと同等のものを直接示すことで、移行を加速します:
| XFINIUM.PDF | IronPDF |
|---|---|
PdfFixedDocument | ChromePdfRenderer |
PdfPage | 自動翻訳 |
page.Graphics.DrawString() | HTMLテキスト要素 |
page.Graphics.DrawImage() | <img>タグ |
page.Graphics.DrawLine() | CSS border または <hr> |
page.Graphics.DrawRectangle() | CSS border on <div> |
PdfStandardFont | CSS font-family |
PdfRgbColor | CSS color |
PdfBrush | CSSプロパティ |
PdfJpegImage | base64付き<img>タグ |
document.Save(stream) | pdf.SaveAs() または pdf.BinaryData |
PdfFlowDocument | RenderHtmlAsPdf() |
| ベンダーサンプルXHTMLコンバーター | RenderHtmlAsPdf() |
一般的な移行の問題と解決策
課題1: 座標ベースのレイアウト
XFINIUM.PDF:すべて正確なX,Y座標が必要で、手動での位置決めが必要です。
ソリューション: HTML/CSSフローレイアウトを使用する。 絶対位置指定が必要な場合は、CSSを使用してください:
.positioned-element {
position: absolute;
top: 100px;
left: 50px;
}
課題2:フォントオブジェクト管理
XFINIUM.PDF: 各フォントに対してPdfUnicodeTrueTypeFontオブジェクトを作成します。
ソリューション: CSS font-familyを使用してください:
<style>
body { font-family: Arial, sans-serif; }
h1 { font-family: 'Times New Roman', serif; font-size: 24px; }
</style>
課題3: カラーハンドリング
XFINIUM.PDF: 色に対してPdfBrushオブジェクトを作成します。
解決策:標準的なCSSの色を使用する:
.header { color: navy; background-color: #f5f5f5; }
.warning { color: rgb(255, 0, 0); }
.info { color: rgba(0, 0, 255, 0.8); }
課題4:マニュアルの改ページ
**XFINIUM.PDF:**Y位置を追跡し、コンテンツがオーバーフローしたときに手動で新しいページを作成します。
ソリューション: IronPDFは自動改ページを処理します。 明示的な制御にはCSSを使用してください:
.section { page-break-after: always; }
.keep-together { page-break-inside: avoid; }
課題5:画像の読み込み
XFINIUM.PDF: ファイルストリームを開き、PdfJpegImageオブジェクトを作成し座標に描画し、ストリームを閉じます。
解決策: HTML <img>タグをファイルパスやbase64データと一緒に使用します。
<img src="image.jpg" width="200" height="150" />
<!-- or -->
<img src="data:image/jpeg;base64,..." />
XFINIUM.PDF移行チェックリスト
マイグレーション前のタスク
コードベースを監査して、すべてのXFINIUM.PDFの使用法を特定してください:
grep -r "using Xfinium.Pdf" --include="*.cs" .
grep -r "Graphics.DrawString\|Graphics.DrawImage\|Graphics.DrawLine" --include="*.cs" .
座標ベースのレイアウトを文書化し、すべてのX,Y位置決め値に注意してください。 フォントおよび色オブジェクトを特定します(PdfBrush)。 PdfFixedDocument.Pages.Add()を使用してマージされたPDFのワークフローをマッピングします。
コード更新タスク
1.Xfinium.Pdf NuGet パッケージの削除
2.IronPDFNuGet パッケージをインストールします
3. 名前空間のインポートをIronPdfに更新します。
4. DrawString()の呼び出しをHTMLのテキスト要素に変換します。
5. <img>タグに変換します。
6. DrawLine()をCSSのボーダーに変換します。
7. PdfStandardFontをCSS font-familyに置き換えます。
8. PdfBrushをCSSの色に置き換えます。
9. ページループのマージをPdfDocument.Merge()に置き換えます。
10.起動時にIronPDFライセンスの初期化を追加する
移行後のテスト
移行後、これらの点を検証してください:
- ビジュアル出力を比較し、外観が期待に一致することを確認する。
- 新しいHTML/CSSアプローチによるテキストレンダリングの検証
- CSSを使用した画像ポジショニングのチェック
- 期待どおりに改ページが行われることを確認
- PDFのセキュリティ設定が正しく適用されていることを確認する
- すべてのターゲットプラットフォームでテスト
IronPDFに移行する主な利点
XFINIUM.PDFからIronPDFに移行することで、いくつかの重要な利点が得られます:
HTML ベースのコンテンツ作成: Web 開発者は既存の HTML および CSS スキルを活用できます。 座標ベースの描画APIを学んだり、フォントやブラシのオブジェクトを管理したりする必要はありません。
自動レイアウト:テキストの折り返し、ページ区切り、フローレイアウトが自動的に行われます。 要素の位置や改ページを手動で計算する必要はありません。
最新の CSS サポート: Flexbox およびグリッド レイアウトを含む完全な CSS3。 レスポンシブデザインはPDFに直接翻訳します。
簡略化されたPDF操作: PdfDocument.Merge()のような一般的な操作に対する単一メソッド呼び出しで、複雑なページを繰り返すループを置き換えます。
アクティブな開発: IronPDFの定期的な更新により、現在 for .NETバージョンとC#言語リリースに追いついている。
広範なドキュメント: XFINIUM.PDF の小規模なエコシステムと比較して、包括的なドキュメント、チュートリアル、サポート リソースを備えた大規模なコミュニティです。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
関連する記事


