フッターコンテンツにスキップ
移行ガイド

C#でPDFSharpからIronPDFに移行する方法

PDFSharpからIronPDFに移行することで、PDF生成のワークフローが手動による座標ベースの描画から最新のHTML/CSSテンプレートに変わります。 このガイドでは、面倒なGDI+スタイルの位置決めをWeb技術に置き換える完全なステップバイステップの移行パスを提供し、開発時間を劇的に短縮し、標準的なHTML/CSSスキルによってPDF生成を保守可能にします。

なぜPDFSharpからIronPDFに移行するのか

PDFSharpを理解する

PDFSharpは低レベルのPDF作成ライブラリとして有名で、開発者はプログラム的なアプローチでPDFドキュメントを生成することができます。 MITライセンスの下でリリースされたPDFSharpは、開発者コミュニティに使用と改変の自由を与えています。 PDFSharpは、主にPDFをゼロから描画してコンパイルするためのツールとして機能します。

PDFSharpは、HTMLからPDFへのコンバータであると誤解されることがありますが、そうではありません。 その目的は、プログラムによるPDF文書作成に特化しています。 HTMLレンダリング機能を提供することを目的としたアドオンHtmlRenderer.PdfSharpがありますが、CSS 2.1のみをサポートしており、フレックスボックスやグリッドのような最新のCSS機能には対応していません。

座標計算問題

PDFSharpのGDI+アプローチは、あなたがしなければならないことを意味します:

  • 各要素の正確なX,Y位置を計算する。
  • ページのオーバーフローのためにコンテンツの高さを手動で追跡する
  • 行の折り返しやテキスト測定を自分で処理する
  • ボーダー計算でセルごとに表を描く
  • 手動改ページで複数ページのドキュメントを管理

PDFSharpのアーキテクチャは、座標を使った位置決めに関する深い理解を必要とし、複雑なレイアウトを作成する際にしばしば課題となります。

PDFSharpとIronPDFの比較

フィーチャー PDFSharp IronPDF
ライセンス MIT (無料) 商用
HTMLからPDFへのサポート なし はい(HTML5/CSS3サポート)
モダンCSSサポート なし(CSS 2.1のみ) はい(フルCSS3)
ドキュメント作成 座標ベースの図面 HTML/CSSテンプレート
レイアウトシステム マニュアルX,Yポジショニング CSS フロー/フレックスボックス/グリッド
改ページ 手計算 自動 + CSS コントロール
テーブル セルを個別に描画 HTML <table>
スタイリング コードベースのフォント/カラー CSSスタイルシート
ドキュメント API 低レベル(座標が必要です) ハイレベル(簡易API)
更新情報 頻度 レギュラー

IronPDFはHTMLドキュメントを完全な忠実度でPDFに変換する必要があるシナリオで輝きを放ちます。 こ for .NETライブラリは、HTML5とCSS3をサポートしており、最新のWeb標準に対応しています。 HTMLからPDFへのネイティブ機能により、開発者は既存のWebコンテンツや最新のWebツールでデザインされたテンプレートを活用することができます。

2025年と2026年まで.NET 10とC# 14の導入を計画しているチームにとって、IronPDFはウェブ開発スキルを活用しながら座標計算を排除する最新のアプローチを提供します。


始める前に

前提条件

  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 PDFSharp
dotnet remove package PdfSharp
dotnet remove package PdfSharp-wpf
dotnet remove package PdfSharp.Charting

# Add IronPDF
dotnet add package IronPdf
# Remove PDFSharp
dotnet remove package PdfSharp
dotnet remove package PdfSharp-wpf
dotnet remove package PdfSharp.Charting

# Add 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

PDFSharpの使用法を特定する

# Find allPDFSharpusages in your codebase
grep -r "PdfSharp\|XGraphics\|XFont\|XBrush\|XPen" --include="*.cs" .
# Find allPDFSharpusages in your codebase
grep -r "PdfSharp\|XGraphics\|XFont\|XBrush\|XPen" --include="*.cs" .
SHELL

完全な API リファレンス

名前空間の変更

// Before: PDFSharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

// After: IronPDF
using IronPdf;
using IronPdf.Editing;
// Before: PDFSharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

// After: IronPDF
using IronPdf;
using IronPdf.Editing;
Imports IronPdf
Imports IronPdf.Editing
$vbLabelText   $csharpLabel

コア API マッピング

PDFSharp API IronPDF API
new PdfDocument() ChromePdfRenderer.RenderHtmlAsPdf()
document.AddPage() 自動翻訳
XGraphics.FromPdfPage() 不要
XGraphics.DrawString() HTML <h1> など
XGraphics.DrawImage() HTML <img> タグ
XFont CSS font-size
XBrush, XPen CSSカラー/ボーダー
document.Save() pdf.SaveAs()
PdfReader.Open() PdfDocument.FromFile()

コード移行の例

例1: HTMLからPDFへの変換

翻訳前(PDFSharp):

// NuGet: Install-Package PdfSharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;

class Program
{
    static void Main()
    {
        //PDFSharpdoes not have built-inHTMLからPDFへconversion
        // You need to manually parse HTML and render content
        PdfDocument document = new PdfDocument();
        PdfPage page = document.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);
        XFont font = new XFont("Arial", 12);

        // マニュアル text rendering (no HTML support)
        gfx.DrawString("Hello from PDFSharp", font, XBrushes.Black,
            new XRect(0, 0, page.Width, page.Height),
            XStringFormats.TopLeft);

        document.Save("output.pdf");
    }
}
// NuGet: Install-Package PdfSharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;

class Program
{
    static void Main()
    {
        //PDFSharpdoes not have built-inHTMLからPDFへconversion
        // You need to manually parse HTML and render content
        PdfDocument document = new PdfDocument();
        PdfPage page = document.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);
        XFont font = new XFont("Arial", 12);

        // マニュアル text rendering (no HTML support)
        gfx.DrawString("Hello from PDFSharp", font, XBrushes.Black,
            new XRect(0, 0, page.Width, page.Height),
            XStringFormats.TopLeft);

        document.Save("output.pdf");
    }
}
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports System

Module Program
    Sub Main()
        ' PDFSharp does not have built-in HTML to PDF conversion
        ' You need to manually parse HTML and render content
        Dim document As New PdfDocument()
        Dim page As PdfPage = document.AddPage()
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
        Dim font As New XFont("Arial", 12)

        ' Manual text rendering (no HTML support)
        gfx.DrawString("Hello from PDFSharp", font, XBrushes.Black, New XRect(0, 0, page.Width, page.Height), XStringFormats.TopLeft)

        document.Save("output.pdf")
    End Sub
End Module
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        //IronPDFhas nativeHTMLからPDFへrendering
        var renderer = new ChromePdfRenderer();

        string html = "<h1>Hello from IronPDF</h1><p>EasyHTMLからPDFへconversion</p>";
        var pdf = renderer.RenderHtmlAsPdf(html);

        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        //IronPDFhas nativeHTMLからPDFへrendering
        var renderer = new ChromePdfRenderer();

        string html = "<h1>Hello from IronPDF</h1><p>EasyHTMLからPDFへconversion</p>";
        var pdf = renderer.RenderHtmlAsPdf(html);

        pdf.SaveAs("output.pdf");
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        ' IronPDF has native HTML to PDF rendering
        Dim renderer As New ChromePdfRenderer()

        Dim html As String = "<h1>Hello from IronPDF</h1><p>Easy HTML to PDF conversion</p>"
        Dim pdf = renderer.RenderHtmlAsPdf(html)

        pdf.SaveAs("output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

この例では、2つのライブラリの最も大きな違いを強調しています。PDFSharpには"HTML から PDF への変換機能は組み込まれていない"と明示的に記載されています。手動で PdfDocument を作成し、PdfPage を追加し、XGraphics オブジェクトを取得し、XFont を作成し、XRect 座標で DrawString() を使用する必要があります。

IronPDF は、ChromePdfRenderer を通じてネイティブ HTML から PDF へのレンダリングを提供します。 RenderHtmlAsPdf() メソッドは HTML 文字列を受け入れ、内部的に Chromium エンジンを使用して変換します。 IronPdfは簡単にHTMLファイルをPDFに変換し、HTML5とCSS3で定義されたすべてのスタイルを保持し、座標計算の必要性を排除します。 包括的な例については、HTML to PDF documentationを参照してください。

例2: 既存のPDFにテキスト/透かしを追加する

翻訳前(PDFSharp):

// NuGet: Install-Package PdfSharp
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
using System;

class Program
{
    static void Main()
    {
        // Open existing PDF
        PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);
        PdfPage page = document.Pages[0];

        // Get graphics object
        XGraphics gfx = XGraphics.FromPdfPage(page);
        XFont font = new XFont("Arial", 20, XFontStyle.Bold);

        // Draw text at specific position
        gfx.DrawString("Watermark Text", font, XBrushes.Red,
            new XPoint(200, 400));

        document.Save("modified.pdf");
    }
}
// NuGet: Install-Package PdfSharp
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
using System;

class Program
{
    static void Main()
    {
        // Open existing PDF
        PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);
        PdfPage page = document.Pages[0];

        // Get graphics object
        XGraphics gfx = XGraphics.FromPdfPage(page);
        XFont font = new XFont("Arial", 20, XFontStyle.Bold);

        // Draw text at specific position
        gfx.DrawString("Watermark Text", font, XBrushes.Red,
            new XPoint(200, 400));

        document.Save("modified.pdf");
    }
}
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Imports PdfSharp.Drawing
Imports System

Module Program
    Sub Main()
        ' Open existing PDF
        Dim document As PdfDocument = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify)
        Dim page As PdfPage = document.Pages(0)

        ' Get graphics object
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
        Dim font As New XFont("Arial", 20, XFontStyle.Bold)

        ' Draw text at specific position
        gfx.DrawString("Watermark Text", font, XBrushes.Red, New XPoint(200, 400))

        document.Save("modified.pdf")
    End Sub
End Module
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        // Open existing PDF
        var pdf = PdfDocument.FromFile("existing.pdf");

        // Add text stamp/watermark
        var textStamper = new TextStamper()
        {
            Text = "Watermark Text",
            FontSize = 20,
            Color = IronSoftware.Drawing.Color.Red,
            VerticalAlignment = VerticalAlignment.Middle,
            HorizontalAlignment = HorizontalAlignment.Center
        };

        pdf.ApplyStamp(textStamper);
        pdf.SaveAs("modified.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;

class Program
{
    static void Main()
    {
        // Open existing PDF
        var pdf = PdfDocument.FromFile("existing.pdf");

        // Add text stamp/watermark
        var textStamper = new TextStamper()
        {
            Text = "Watermark Text",
            FontSize = 20,
            Color = IronSoftware.Drawing.Color.Red,
            VerticalAlignment = VerticalAlignment.Middle,
            HorizontalAlignment = HorizontalAlignment.Center
        };

        pdf.ApplyStamp(textStamper);
        pdf.SaveAs("modified.pdf");
    }
}
Imports IronPdf
Imports IronPdf.Editing
Imports System

Module Program
    Sub Main()
        ' Open existing PDF
        Dim pdf = PdfDocument.FromFile("existing.pdf")

        ' Add text stamp/watermark
        Dim textStamper = New TextStamper() With {
            .Text = "Watermark Text",
            .FontSize = 20,
            .Color = IronSoftware.Drawing.Color.Red,
            .VerticalAlignment = VerticalAlignment.Middle,
            .HorizontalAlignment = HorizontalAlignment.Center
        }

        pdf.ApplyStamp(textStamper)
        pdf.SaveAs("modified.pdf")
    End Sub
End Module
$vbLabelText   $csharpLabel

PDFSharp では、PdfReader.Open()PdfDocumentOpenMode.Modify を指定して PDF を開き、ページにアクセスし、XGraphics オブジェクトを作成し、スタイル付きの XFont を作成し、XPoint で正確な X、Y 座標 (200、400) を指定して DrawString() を使用する必要があります。

IronPDF は、宣言型プロパティを持つ TextStamper オブジェクト (HorizontalAlignment)、および ApplyStamp() を使用してこれを簡素化します。 座標計算の必要はありません。アライメントを指定するだけで、IronPDFが位置決めを行います。 スタンプ機能には IronPdf.Editing 名前空間が必要であることに注意してください。

例3: 画像でPDFを作成する

翻訳前(PDFSharp):

// NuGet: Install-Package PdfSharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;

class Program
{
    static void Main()
    {
        // Create new PDF document
        PdfDocument document = new PdfDocument();
        PdfPage page = document.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);

        // Load and draw image
        XImage image = XImage.FromFile("image.jpg");

        // Calculate size to fit page
        double width = 200;
        double height = 200;

        gfx.DrawImage(image, 50, 50, width, height);

        // Add text
        XFont font = new XFont("Arial", 16);
        gfx.DrawString("Image in PDF", font, XBrushes.Black,
            new XPoint(50, 270));

        document.Save("output.pdf");
    }
}
// NuGet: Install-Package PdfSharp
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System;

class Program
{
    static void Main()
    {
        // Create new PDF document
        PdfDocument document = new PdfDocument();
        PdfPage page = document.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);

        // Load and draw image
        XImage image = XImage.FromFile("image.jpg");

        // Calculate size to fit page
        double width = 200;
        double height = 200;

        gfx.DrawImage(image, 50, 50, width, height);

        // Add text
        XFont font = new XFont("Arial", 16);
        gfx.DrawString("Image in PDF", font, XBrushes.Black,
            new XPoint(50, 270));

        document.Save("output.pdf");
    }
}
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports System

Module Program
    Sub Main()
        ' Create new PDF document
        Dim document As New PdfDocument()
        Dim page As PdfPage = document.AddPage()
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

        ' Load and draw image
        Dim image As XImage = XImage.FromFile("image.jpg")

        ' Calculate size to fit page
        Dim width As Double = 200
        Dim height As Double = 200

        gfx.DrawImage(image, 50, 50, width, height)

        ' Add text
        Dim font As New XFont("Arial", 16)
        gfx.DrawString("Image in PDF", font, XBrushes.Black, New XPoint(50, 270))

        document.Save("output.pdf")
    End Sub
End Module
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        // Create PDF from HTML with image
        var renderer = new ChromePdfRenderer();

        string html = @"
            <h1>Image in PDF</h1>
            <img src='image.jpg' style='width:200px; height:200px;' />
            <p>Easy image embedding with HTML</p>";

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

        // Alternative: Add image to existing PDF
        var existingPdf = new ChromePdfRenderer().RenderHtmlAsPdf("<h1>Document</h1>");
        var imageStamper = new IronPdf.Editing.ImageStamper(new Uri("image.jpg"))
        {
            VerticalAlignment = IronPdf.Editing.VerticalAlignment.Top
        };
        existingPdf.ApplyStamp(imageStamper);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        // Create PDF from HTML with image
        var renderer = new ChromePdfRenderer();

        string html = @"
            <h1>Image in PDF</h1>
            <img src='image.jpg' style='width:200px; height:200px;' />
            <p>Easy image embedding with HTML</p>";

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

        // Alternative: Add image to existing PDF
        var existingPdf = new ChromePdfRenderer().RenderHtmlAsPdf("<h1>Document</h1>");
        var imageStamper = new IronPdf.Editing.ImageStamper(new Uri("image.jpg"))
        {
            VerticalAlignment = IronPdf.Editing.VerticalAlignment.Top
        };
        existingPdf.ApplyStamp(imageStamper);
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        ' Create PDF from HTML with image
        Dim renderer = New ChromePdfRenderer()

        Dim html As String = "
            <h1>Image in PDF</h1>
            <img src='image.jpg' style='width:200px; height:200px;' />
            <p>Easy image embedding with HTML</p>"

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

        ' Alternative: Add image to existing PDF
        Dim existingPdf = New ChromePdfRenderer().RenderHtmlAsPdf("<h1>Document</h1>")
        Dim imageStamper = New IronPdf.Editing.ImageStamper(New Uri("image.jpg")) With {
            .VerticalAlignment = IronPdf.Editing.VerticalAlignment.Top
        }
        existingPdf.ApplyStamp(imageStamper)
    End Sub
End Class
$vbLabelText   $csharpLabel

PDFSharp では、新しい PdfDocument を作成し、PdfPage を追加し、XGraphics を取得し、ファイルから XImage をロードし、正確な座標 (50, 50, 200, 200) で DrawImage() を使用して幅と高さを計算し、次に DrawString() を使用してテキストを個別に追加する必要があります。

IronPDF は、<img> タグと CSS スタイル (style='width:200px;) を使用した標準 HTML を使用します。 高さ:200px;')。 座標計算は不要で、CSSがレイアウトを処理します。IronPDFには、宣言的な配置プロパティを使用して既存の PDF に画像を追加するための ImageStamper も用意されています。 詳しくは、チュートリアルをご覧ください。


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

パラダイムシフト:座標からHTML/CSSへ

最も大きな変更点は、座標ベースの描画からHTML/CSSへの移行です:

// PDFSharp: マニュアル positioning nightmare
gfx.DrawString("Invoice", titleFont, XBrushes.Black, new XPoint(50, 50));
gfx.DrawString("Customer: John", bodyFont, XBrushes.Black, new XPoint(50, 80));

// IronPDF: Let CSS handle layout
var html = @"
<div style='padding: 50px;'>
    <h1>Invoice</h1>
    <p>Customer: John</p>
</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
// PDFSharp: マニュアル positioning nightmare
gfx.DrawString("Invoice", titleFont, XBrushes.Black, new XPoint(50, 50));
gfx.DrawString("Customer: John", bodyFont, XBrushes.Black, new XPoint(50, 80));

// IronPDF: Let CSS handle layout
var html = @"
<div style='padding: 50px;'>
    <h1>Invoice</h1>
    <p>Customer: John</p>
</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
Imports PdfSharp.Drawing
Imports IronPdf

' PDFSharp: マニュアル positioning nightmare
gfx.DrawString("Invoice", titleFont, XBrushes.Black, New XPoint(50, 50))
gfx.DrawString("Customer: John", bodyFont, XBrushes.Black, New XPoint(50, 80))

' IronPDF: Let CSS handle layout
Dim html As String = "
<div style='padding: 50px;'>
    <h1>Invoice</h1>
    <p>Customer: John</p>
</div>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
$vbLabelText   $csharpLabel

フォントの移行

// PDFSharp: XFont objects
var titleFont = new XFont("Arial", 24, XFontStyle.Bold);
var bodyFont = new XFont("Times New Roman", 12);

// IronPDF: CSS font properties
var html = @"
<style>
    h1 { font-family: Arial, sans-serif; font-size: 24px; font-weight: bold; }
    p { font-family: 'Times New Roman', serif; font-size: 12px; }
</style>";
// PDFSharp: XFont objects
var titleFont = new XFont("Arial", 24, XFontStyle.Bold);
var bodyFont = new XFont("Times New Roman", 12);

// IronPDF: CSS font properties
var html = @"
<style>
    h1 { font-family: Arial, sans-serif; font-size: 24px; font-weight: bold; }
    p { font-family: 'Times New Roman', serif; font-size: 12px; }
</style>";
Dim titleFont As New XFont("Arial", 24, XFontStyle.Bold)
Dim bodyFont As New XFont("Times New Roman", 12)

Dim html As String = "
<style>
    h1 { font-family: Arial, sans-serif; font-size: 24px; font-weight: bold; }
    p { font-family: 'Times New Roman', serif; font-size: 12px; }
</style>"
$vbLabelText   $csharpLabel

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

// PDFSharp: PdfReader.Open()
PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);

// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("existing.pdf");
// PDFSharp: PdfReader.Open()
PdfDocument document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);

// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("existing.pdf");
Imports PdfSharp
Imports IronPDF

' PDFSharp: PdfReader.Open()
Dim document As PdfDocument = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify)

' IronPDF: PdfDocument.FromFile()
Dim pdf = PdfDocument.FromFile("existing.pdf")
$vbLabelText   $csharpLabel

保存メソッドの変更

// PDFSharp: document.Save()
document.Save("output.pdf");

// IronPDF: pdf.SaveAs()
pdf.SaveAs("output.pdf");
// PDFSharp: document.Save()
document.Save("output.pdf");

// IronPDF: pdf.SaveAs()
pdf.SaveAs("output.pdf");
$vbLabelText   $csharpLabel

ページのアクセス変更

// PDFSharp: document.Pages[0]
PdfPage page = document.Pages[0];

// IronPDF:自動翻訳page handling or pdf.Pages[0]
// Pages are created automatically from HTML content
// PDFSharp: document.Pages[0]
PdfPage page = document.Pages[0];

// IronPDF:自動翻訳page handling or pdf.Pages[0]
// Pages are created automatically from HTML content
$vbLabelText   $csharpLabel

移行後の新機能

IronPDFに移行することで、PDFSharpが提供できない機能を得ることができます:

ネイティブ HTML から PDF

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Modern Web Content</h1>");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Modern Web Content</h1>");
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Modern Web Content</h1>")
$vbLabelText   $csharpLabel

URLをPDFに

var pdf = renderer.RenderUrlAsPdf("https://example.com");
var pdf = renderer.RenderUrlAsPdf("https://example.com");
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
$vbLabelText   $csharpLabel

PDFマージ

var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
$vbLabelText   $csharpLabel

HTMLによるウォーターマーク

pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>")
$vbLabelText   $csharpLabel

機能比較の概要

フィーチャー PDFSharp IronPDF
座標ベースの図面 ✗ (HTMLを使用)
HTMLからPDFへ
CSS3 サポート
フレックスボックス/グリッドレイアウト
テキストスタンプ マニュアル XGraphics テキストスタンパー
画像スタンプ マニュアル XImage イメージスタンパー
PDFのマージ マニュアル
URLからPDFへ
最新のウェブレンダリング Chromium エンジン
自動改ページ

移行チェックリスト

移行前

  • コードベース内のすべてのPDFSharpの使用状況を一覧表示する
  • 生成される文書の種類(レポート、請求書、証明書)を識別する
  • カスタムグラフィックや描画操作をメモします
  • IronPDFライセンス キーの保存を計画する (環境変数を推奨)
  • まずはIronPDFの試用ライセンスでテストしてください

パッケージの変更

  • PdfSharp NuGetパッケージを削除します
  • 使用されている場合は、PdfSharp-wpf NuGetパッケージを削除します
  • 使用されている場合は、PdfSharp.Charting NuGetパッケージを削除します
  • IronPdf NuGetパッケージをインストールします: dotnet add package IronPdf

コードの変更

  • 名前空間のインポートを更新します (using PdfSharp.Pdf;using IronPdf;)
  • スタンプ機能のためにusing IronPdf.Editing;を追加します
  • 座標ベースのレイアウトをHTML/CSSに変換する
  • XFont を CSS フォントプロパティに置き換えます
  • XPen を CSS の色/境界線に置き換えます
  • XGraphics.DrawString() を HTML テキスト要素に置き換えます
  • XGraphics.DrawImage() を HTML <img> タグに置き換えます
  • PdfReader.Open()PdfDocument.FromFile() に置き換えます
  • document.Save()pdf.SaveAs() に置き換えます
  • テーブル描画コードをHTMLテーブルに変換する

移行後

  • 生成されたPDFの視覚的な比較
  • 複数ページのドキュメントをテストする
  • フォントレンダリングを確認する
  • 必要に応じて新しい機能(HTMLからPDF、結合、透かし)を追加します

カーティス・チャウ
テクニカルライター

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

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

アイアンサポートチーム

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