製品比較

PDFSharp HTML to PDF の例とチュートリアルの比較

更新済み 8月 11, 2024
共有:

イントロダクション

.NETでPDFドキュメントを管理する際、開発者はそれぞれ独自の特徴や機能を持つさまざまなライブラリから選択することができます。 これらの中で、 IronPDF そしてPDFsharpは、さまざまなニーズや好みに対応する際立った選択肢として際立っています。

この記事では、これらのライブラリが提供するさまざまな機能、それに伴うサポート、料金、ドキュメント、および互換性について詳しく見ていきます。

IronPDFとPDFsharpの概要

強力なPDFライブラリであるIronPDFは、開発者がPDFコンテンツを簡単に作成、編集、および抽出することを可能にします。 ユーザーはIronPDFを使用して、HTML、ASPX、MVC、画像などのさまざまな形式をPDFドキュメントに変換することができます。 IronPDF テキスト編集、画像操作、メタデータ変更、ウォーターマークの追加、PDFファイルの暗号化など、数多くの機能があります。 開発者がPDFドキュメントを扱いやすくするための使いやすいインターフェースと印象的な機能セットを備えていることが知られています。

PDFsharpは、PDFドキュメントの動的生成に焦点を当てた.NETベースのオープンソースライブラリです。 この製品は、テキスト、グラフィックス、画像の描画をサポートするC#で完全に実装されています。 また、既存のPDFファイルの結合や分割のような変更操作も可能です。 PDFsharpは、追加機能が多く付いたものではなく、シンプルなPDFファイルを操作するための最低限のライブラリを探している方に適しています。

クロスプラットフォーム互換性

IronPDFとPDFsharpはどちらも.NET環境内で動作します。PDFsharpはバージョン6.1から、.NET Framework 4.7.2以上、.NET Standard 2.0および.NET 6以上のバージョンをサポートしており、Windowsだけでなく、LinuxやmacOSなどの.NET互換プラットフォームでも動作します。

IronPDF 最新のプラットフォーム互換性をサポートし、さまざまな.NETバージョンで動作可能です。これにより、開発者はWindows、Linux、Mac、Azure、Docker、そしてAWSなどのアプリケーション環境で作業でき、多くのオペレーティングシステムや開発環境との普遍的な互換性が保証されます。

IronPDF:

  • .NETバージョン:

    • (C#、VB.NET、F#)

    • .NETコア (8, 7, 6, 5, および3.1+)

    • .NETスタンダード (2.0以上)
  • .NETフレームワーク (4.6.2+)
  • .NETプロジェクトタイプ: Blazor、MAUI、WPF、コンソールアプリケーションなどのプロジェクトタイプで動作します
  • アプリ環境: IronPDFは、Windows、Linux、Mac、Docker、Azure、およびAWSを含むアプリ環境で動作します。
  • IDEs: Microsoft Visual Studio や JetBrains Rider & ReSharper などの IDEs と互換性があります

PDFsharp

  • .NET バージョン:

    • .NETフレームワーク (4.7.2+)

    • .NETスタンダード (2.0以上)
  • .NET 6+
  • .NETプロジェクトの種類: Blazor、MAUI、ASP.NETなどのプロジェクトタイプや技術と連携可能

  • アプリケーション環境: PDFsharpは、Windows、macOS、Linuxで動作するプロジェクトをサポートしています。

機能比較概要:IronPDF vs. PDFsharp

IronPDF PDFファイルを操作するためのさまざまな機能を提供し、PDFの生成、変更、コンテンツの抽出、HTML、ASPX、MVC、画像のPDF形式への変換、テキスト、画像、メタデータの編集が可能です。 PDFページにウォーターマークを適用するか、PDFファイルを暗号化する。

一方、PDFsharpは、PFDドキュメントの作成および操作に重点を置いています。 ページにテキストラインや段落を描画したり、四角形や円などのグラフィックをページに挿入することができます。

IronPDF (アイアンPDF)

  • HTMLからPDFへの変換: IronPDFは最新のウェブ標準をサポートしています (CSS3、HTML5、JavaScript)高忠実度PDFドキュメントの作成を可能にします。
  • PDF暗号化: ユーザーはIronPDFの強力な暗号化ツールを利用してPDFファイルを暗号化および復号化し、PDFファイルに追加のセキュリティ層を追加することができます。
  • PDF編集: IronPDFライブラリには、既存のPDFファイルの結合、分割、フォーマット、修正機能が含まれています。
  • PDFファイルのデジタル署名: IronPDFはユーザーにPDFにデジタル署名をすることを可能にします。
  • 透かし: 簡単にテキストと画像の透かしをPDFファイルに適用できます。 HTML/CSSを使用してプロセスを完全に制御することを活用してください。
  • PDFスタンピング: IronPDFを使用してPDFドキュメントに画像やテキストをスタンプします。

PDFsharp:

  • PDFを作成する: PDFsharpは、任意の.NET言語からPDFファイルを作成および生成できます
  • PDF操作: PDFの編集、結合、分割
  • PDFファイルにグラフィックを描画する: PDFsharpを使用すると、PDFドキュメントに形状、線、画像を描画することができます
  • 暗号化: PDFsharpの暗号化ツールでPDFファイルを暗号化します

IronPDFとPDFsharpの機能比較

HTMLをPDFに変換

さまざまな職場や環境で、変換 HTMLからPDF 簡単ではあるが必要な作業です。 このプロセスにおけるIronPDFとPDFsharpの比較は、以下のコード例に示されています。

IronPDF:

using IronPdf;

// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or Stream
pdf.SaveAs("output.pdf");

// Advanced Example with HTML Assets
// Load external html assets: images, CSS and JavaScript.
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
using IronPdf;

// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

// Export to a file or Stream
pdf.SaveAs("output.pdf");

// Advanced Example with HTML Assets
// Load external html assets: images, CSS and JavaScript.
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Imports IronPdf

' Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = True

' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()

' Create a PDF from a HTML string using C#
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

' Advanced Example with HTML Assets
' Load external html assets: images, CSS and JavaScript.
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")
VB   C#

PDFsharp:

PDFsharpだけでは、HTMLからPDFへの変換を処理できません。 代わりに、このタスクを実行するためにHtmlRenderer.PdfSharpライブラリが必要です。 このHTMLレンダラーは、静的レンダリングコードを使用してHTMLをPDFに変換できます。

using System.IO;
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;

static void Main(string[] args)
{
    string html = @"<h1>Hello World</h1>";
    PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4);
    const string filename = "HtmlToPdfExample.pdf";
    pdf.Save(filename);
}
using System.IO;
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;

static void Main(string[] args)
{
    string html = @"<h1>Hello World</h1>";
    PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4);
    const string filename = "HtmlToPdfExample.pdf";
    pdf.Save(filename);
}
Imports System.IO
Imports PdfSharp.Pdf
Imports TheArtOfDev.HtmlRenderer.PdfSharp

Shared Sub Main(ByVal args() As String)
	Dim html As String = "<h1>Hello World</h1>"
	Dim pdf As PdfDocument = PdfGenerator.GeneratePdf(html, PageSize.A4)
	Const filename As String = "HtmlToPdfExample.pdf"
	pdf.Save(filename)
End Sub
VB   C#

IronPDFは、HTMLコード、HTMLスニペット、またはHTMLテンプレートをPDF形式に変換する便利で簡単な方法を提供し、ユーザーに多くの制御を許可します。 IronPDFはモダンなウェブ標準に完全対応しており、元のウェブページに忠実なPDFファイルを作成することができます。

一方、PDFsharpは現在、HTMLからPDFへの変換をサポートしておらず、HTMLファイルを解析する機能もありません。 代わりに、HtmlRenderer.PdfSharpライブラリをPDFsharpと一緒に使用して、このタスクを完了することができます。

PDFファイル内のテキストを編集する

時々、ユーザーは 編集する PDFファイルの一部、特にプライベートまたは機密情報を扱う場合。

IronPDF:

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact the 'are' phrase from all pages
pdf.RedactTextOnAllPages("are");

pdf.SaveAs("redacted.pdf");
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact the 'are' phrase from all pages
pdf.RedactTextOnAllPages("are");

pdf.SaveAs("redacted.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("novel.pdf")

' Redact the 'are' phrase from all pages
pdf.RedactTextOnAllPages("are")

pdf.SaveAs("redacted.pdf")
VB   C#

PDFsharp:

PDFsharpは、現在PDFコンテンツの編集に関する組み込み機能を提供していません。 ただし、機密情報を永久に削除または隠すことが伴うため、PDFsharpのグラフィックス描画ツールを使用して、編集したい内容を手動で描画することによって、同様の結果を達成することができます。 以下はその実現方法の一例です:

using System;
using PdfSharp.Pdf;
using PdfSharp.Drawing;

namespace PdfRedactionExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load an existing PDF document
            PdfDocument document = PdfReader.Open("input.pdf", PdfDocumentOpenMode.Modify);
            // Get the first page of the document
            PdfPage page = document.Pages[0];
            // Create a graphics object to write on the page
            XGraphics gfx = XGraphics.FromPdfPage(page);
            // Define the area to redact (for example, a rectangle covering text)
            XRect redactRect = new XRect(100, 100, 200, 50); // Adjust coordinates and size as needed
            // Fill the redaction area with a black rectangle
            gfx.DrawRectangle(XBrushes.Black, redactRect);
            // Save the modified document
            document.Save("output.pdf");
            // Optionally, close the document
            document.Close();
        }
    }
}
using System;
using PdfSharp.Pdf;
using PdfSharp.Drawing;

namespace PdfRedactionExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load an existing PDF document
            PdfDocument document = PdfReader.Open("input.pdf", PdfDocumentOpenMode.Modify);
            // Get the first page of the document
            PdfPage page = document.Pages[0];
            // Create a graphics object to write on the page
            XGraphics gfx = XGraphics.FromPdfPage(page);
            // Define the area to redact (for example, a rectangle covering text)
            XRect redactRect = new XRect(100, 100, 200, 50); // Adjust coordinates and size as needed
            // Fill the redaction area with a black rectangle
            gfx.DrawRectangle(XBrushes.Black, redactRect);
            // Save the modified document
            document.Save("output.pdf");
            // Optionally, close the document
            document.Close();
        }
    }
}
Imports System
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing

Namespace PdfRedactionExample
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			' Load an existing PDF document
			Dim document As PdfDocument = PdfReader.Open("input.pdf", PdfDocumentOpenMode.Modify)
			' Get the first page of the document
			Dim page As PdfPage = document.Pages(0)
			' Create a graphics object to write on the page
			Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
			' Define the area to redact (for example, a rectangle covering text)
			Dim redactRect As New XRect(100, 100, 200, 50) ' Adjust coordinates and size as needed
			' Fill the redaction area with a black rectangle
			gfx.DrawRectangle(XBrushes.Black, redactRect)
			' Save the modified document
			document.Save("output.pdf")
			' Optionally, close the document
			document.Close()
		End Sub
	End Class
End Namespace
VB   C#

PDFファイルのコンテンツを編集する場合、IronPDFはPDFドキュメントから直接テキストを編集するためのわかりやすい方法を提供します。 ユーザーはすべてのページで編集するテキストを簡単に指定することができ、直感的で簡潔なAPIにより、迅速かつ効率的に作業を行うことができます。

一方、PDFsharpには現在、組み込みの編集機能がありません。 ただし、ユーザーはグラフィックス描画機能を利用して手動でコンテンツにオーバーレイを追加することで修正することができますが、このアプローチはより手動の介入とカスタマイズを必要とします。

PDFファイルにデジタル署名する

必要がある場合 PDFドキュメントに署名する デジタルで行うと非常に時間がかかることがあります。 プログラムでそれを行うことによって、その時間の一部を節約する方法があります。 以下のコード例では、IronPDF と PDFsharp の間でドキュメント署名の動作方法を比較します。

IronPDF:

using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;

// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);

// Create PdfSignature object
var sig = new PdfSignature(cert);

// Sign PDF document
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;

// Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable);

// Create PdfSignature object
var sig = new PdfSignature(cert);

// Sign PDF document
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
pdf.Sign(sig);
pdf.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates

' Create X509Certificate2 object with X509KeyStorageFlags set to Exportable
Private cert As New X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable)

' Create PdfSignature object
Private sig = New PdfSignature(cert)

' Sign PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("document.pdf")
pdf.Sign(sig)
pdf.SaveAs("signed.pdf")
VB   C#

PDFsharp:

PDFsharpはPDFファイルにデジタル署名するためのサポートを内蔵しておらず、このタスクを完了するためにiTextSharpなどの外部ライブラリに依存しています。

PDF文書にデジタル署名をプログラムで付けることは、ワークフローを大幅に簡素化できます。 IronPDFにはデジタル署名のサポートが組み込まれており、数行のコードでタスクを完了することができるため、プロセスは簡単でシンプルです。 しかし、PDFsharpにはデジタル署名機能が組み込まれていないため、iTextSharpなどのサードパーティライブラリが必要となり、実装がさらに複雑になります。

PDFにウォーターマークを適用

プライベートな文書、著作権保護、ブランディング、またはその他の機密記録を伴うタスクを扱う場合; 適用してパーソナライズする能力 透かし PDFファイルで非常に便利です。 この記事では、PDFドキュメントに透かしを追加する際のIronPDFとPDFsharpの比較を行います。

IronPDF:

using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
using IronPdf;

// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf

' Stamps a Watermark onto a new or existing PDF
Private renderer = New ChromePdfRenderer()

Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("C:\Path\To\Watermarked.pdf")
VB   C#

PDFsharp:

using PdfSharp.Pdf;
using PdfSharp.Drawing;

PdfDocument document = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify);
XGraphics gfx = XGraphics.FromPdfPage(document.Pages[0]);
XFont font = new XFont("Verdana", 40, XFontStyle.BoldItalic);
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));
string watermarkText = "SAMPLE";
XSize textSize = gfx.MeasureString(watermarkText, font);
XPoint center = new XPoint((document.Pages[0].Width - textSize.Width) / 2, (document.Pages[0].Height - textSize.Height) / 2);
gfx.DrawString(watermarkText, font, brush, center, XStringFormats.Center);

// Save the document
document.Save("Watermarked.pdf");
using PdfSharp.Pdf;
using PdfSharp.Drawing;

PdfDocument document = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify);
XGraphics gfx = XGraphics.FromPdfPage(document.Pages[0]);
XFont font = new XFont("Verdana", 40, XFontStyle.BoldItalic);
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));
string watermarkText = "SAMPLE";
XSize textSize = gfx.MeasureString(watermarkText, font);
XPoint center = new XPoint((document.Pages[0].Width - textSize.Width) / 2, (document.Pages[0].Height - textSize.Height) / 2);
gfx.DrawString(watermarkText, font, brush, center, XStringFormats.Center);

// Save the document
document.Save("Watermarked.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing

Private document As PdfDocument = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify)
Private gfx As XGraphics = XGraphics.FromPdfPage(document.Pages(0))
Private font As New XFont("Verdana", 40, XFontStyle.BoldItalic)
Private brush As XBrush = New XSolidBrush(XColor.FromArgb(128, 255, 0, 0))
Private watermarkText As String = "SAMPLE"
Private textSize As XSize = gfx.MeasureString(watermarkText, font)
Private center As New XPoint((document.Pages(0).Width - textSize.Width) \ 2, (document.Pages(0).Height - textSize.Height) \ 2)
gfx.DrawString(watermarkText, font, brush, center, XStringFormats.Center)

' Save the document
document.Save("Watermarked.pdf")
VB   C#

PDF ドキュメントに透かしを追加することは、プライバシー保護、著作権保護、およびブランディングに関わるタスクにおいて重要です。 IronPDFは、HTML/CSSを使用してカスタムウォーターマークを効率的に適用できるシンプルなAPIを提供し、柔軟性と実装の容易さを提供しつつ、ユーザーにプロセスの多くの制御を可能にします。 一方、PDFsharpはPDFページにウォーターマークを重ねるために、グラフィックやテキスト描画メソッドを利用して手動での処理が必要です。

DOCXからPDFファイルへの変換

異なるファイルタイプをPDFに変換することは、PDFファイルの作成において重要です。 この場合、私たちは~に集中します DOCXファイルタイプ そして、IronPDFとPDFsharpがこのタスクを達成する方法を比較します。

IronPDF:

using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");

// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");

// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");
Imports IronPdf

' Instantiate Renderer
Private renderer As New DocxToPdfRenderer()

' Render from DOCX file
Private pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")

' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")
VB   C#

PDFsharp:

PDFsharpは現在、DOCXをPDFファイル形式に直接変換することをサポートしていません。 代わりに、ユーザーがこのタスクを実行したい場合、DocXなどの外部ライブラリを使用する必要があります。

DOCXからPDFへの変換に関して、IronPDFはこの作業に対してシンプルで簡潔なアプローチを提供し、DocxToPdfRendererを通じてDOCXからPDFへの変換を直接サポートします。 これにより、生成されたPDFのシームレスなレンダリングと保存が可能になります。

PDFsharpはネイティブでDOCXからPDFへの変換をサポートしていません。 ユーザーはこの機能を実現するために、DocXのような外部ライブラリに依存する必要があります。

PDFに画像やテキストをスタンプする

場合によっては、透かしを適用する際などに、PDFページを スタンプ付き 何かが書かれているもので。 このセクションでは、IronPDFのスタンピング機能とPDFsharpをPDF文書で比較します。

IronPDF:

using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create text stamper
TextStamper textStamper = new TextStamper()
{
    Text = "Text Stamper!",
    FontFamily = "Bungee Spice",
    UseGoogleFont = true,
    FontSize = 30,
    IsBold = true,
    IsItalic = true,
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");
using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create text stamper
TextStamper textStamper = new TextStamper()
{
    Text = "Text Stamper!",
    FontFamily = "Bungee Spice",
    UseGoogleFont = true,
    FontSize = 30,
    IsBold = true,
    IsItalic = true,
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the text stamper
pdf.ApplyStamp(textStamper);
pdf.SaveAs("stampText.pdf");

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);
pdf.SaveAs("stampImage.pdf");
Imports IronPdf
Imports IronPdf.Editing

Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create text stamper
Private textStamper As New TextStamper() With {
	.Text = "Text Stamper!",
	.FontFamily = "Bungee Spice",
	.UseGoogleFont = True,
	.FontSize = 30,
	.IsBold = True,
	.IsItalic = True,
	.VerticalAlignment = VerticalAlignment.Top
}

' Stamp the text stamper
pdf.ApplyStamp(textStamper)
pdf.SaveAs("stampText.pdf")

' Create image stamper
Dim imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}

' Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0)
pdf.SaveAs("stampImage.pdf")
VB   C#

PDFsharp:

using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System.Drawing;

// Load an existing PDF document
PdfDocument document = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify);
// Iterate through each page in the document
 foreach (PdfPage page in document.Pages)
 {
    // Get an XGraphics object for drawing on the page
    XGraphics gfx = XGraphics.FromPdfPage(page);

    // Define a font and brush for stamping text
    XFont font = new XFont("Arial", 12);
    XBrush brush = XBrushes.Red;

     // Stamp text onto the page
     gfx.DrawString("Confidential", font, brush, 50, 50);

     // Stamp an image onto the page
     XImage image = XImage.FromFile("stamp.png"); // Replace with your image path
     gfx.DrawImage(image, 100, 100, image.PixelWidth / 2, image.PixelHeight / 2);
}

document.Save("StampedOutput.pdf");
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System.Drawing;

// Load an existing PDF document
PdfDocument document = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify);
// Iterate through each page in the document
 foreach (PdfPage page in document.Pages)
 {
    // Get an XGraphics object for drawing on the page
    XGraphics gfx = XGraphics.FromPdfPage(page);

    // Define a font and brush for stamping text
    XFont font = new XFont("Arial", 12);
    XBrush brush = XBrushes.Red;

     // Stamp text onto the page
     gfx.DrawString("Confidential", font, brush, 50, 50);

     // Stamp an image onto the page
     XImage image = XImage.FromFile("stamp.png"); // Replace with your image path
     gfx.DrawImage(image, 100, 100, image.PixelWidth / 2, image.PixelHeight / 2);
}

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

' Load an existing PDF document
Private document As PdfDocument = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify)
' Iterate through each page in the document
 For Each page As PdfPage In document.Pages
	' Get an XGraphics object for drawing on the page
	Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

	' Define a font and brush for stamping text
	Dim font As New XFont("Arial", 12)
	Dim brush As XBrush = XBrushes.Red

	 ' Stamp text onto the page
	 gfx.DrawString("Confidential", font, brush, 50, 50)

	 ' Stamp an image onto the page
	 Dim image As XImage = XImage.FromFile("stamp.png") ' Replace with your image path
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
	 gfx.DrawImage(image, 100, 100, image.PixelWidth / 2, image.PixelHeight / 2)
 Next page

document.Save("StampedOutput.pdf")
VB   C#

IronPDFは、ユーザーがテキストや画像をPDFドキュメントに簡単に追加できるようにし、プロセスをわかりやすくシンプルに保ちます。 ユーザーにプロセスのすべての側面を完全に制御する力を与え、特にHTML/CSSに慣れている人にとっては非常に有利です。

一方で、PDFsharpはXGraphicsオブジェクトを使用した手動処理が必要で、テキストや画像を特定の座標やグラフィカルパラメータを使って各ページに直接スタンプします。

PDFファイルの暗号化

オフィス、学校、図書館のいずれの場所でも、 暗号化と復号化 PDFドキュメントは、多くの作業環境の一部を構成しています。 したがって、この機能を問題なく実行できるプログラムがあることは、非常に重要です。 このセクションでは、IronPDFとPDFsharpがPDF暗号化タスクをどのように処理するかを比較します。

IronPDF:

using IronPdf;
using System;

// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;

// Edit file security settings
// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
using IronPdf;
using System;

// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = DateTime.Now;

// Edit file security settings
// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// change or set the document encryption password
pdf.Password = "my-password";
pdf.SaveAs("secured.pdf");
Imports IronPdf
Imports System

' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")

' Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = DateTime.Now

' Edit file security settings
' The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights

' change or set the document encryption password
pdf.Password = "my-password"
pdf.SaveAs("secured.pdf")
VB   C#

PDFsharp:

PDFsharp単独では、PDF暗号化のサポートが組み込まれていません。 しかし、ユーザーはこのタスクを実行するために PdfSharp.Pdf.IOライブラリをインストールすることができます。

using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Security;

PdfDocument document = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify);
string userPassword = "userpassword";
string ownerPassword = "ownerpassword";

PdfSecuritySettings securitySettings = document.SecuritySettings;
securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted128Bit;
securitySettings.UserPassword = userPassword;
securitySettings.OwnerPassword = ownerPassword;
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotationsAndFieldsEdit = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = true;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = true;

document.Save("EncryptedOutput.pdf");
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Security;

PdfDocument document = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify);
string userPassword = "userpassword";
string ownerPassword = "ownerpassword";

PdfSecuritySettings securitySettings = document.SecuritySettings;
securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted128Bit;
securitySettings.UserPassword = userPassword;
securitySettings.OwnerPassword = ownerPassword;
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotationsAndFieldsEdit = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = true;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = true;

document.Save("EncryptedOutput.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Imports PdfSharp.Pdf.Security

Private document As PdfDocument = PdfReader.Open("Input.pdf", PdfDocumentOpenMode.Modify)
Private userPassword As String = "userpassword"
Private ownerPassword As String = "ownerpassword"

Private securitySettings As PdfSecuritySettings = document.SecuritySettings
securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted128Bit
securitySettings.UserPassword = userPassword
securitySettings.OwnerPassword = ownerPassword
securitySettings.PermitAccessibilityExtractContent = False
securitySettings.PermitAnnotationsAndFieldsEdit = False
securitySettings.PermitAssembleDocument = False
securitySettings.PermitExtractContent = False
securitySettings.PermitFormsFill = True
securitySettings.PermitFullQualityPrint = True
securitySettings.PermitModifyDocument = True
securitySettings.PermitPrint = True

document.Save("EncryptedOutput.pdf")
VB   C#

IronPDFは、強力な暗号化機能を備えた堅牢なツールで、PDFを簡単に暗号化し、読み取り専用アクセス、コピー貼り付け制限、印刷許可などのセキュリティ設定を管理できます。 暗号化されたファイルにパスワード保護を追加し、メタデータをカスタマイズすることもできます。 要するに、IronPDFは安全なPDF管理のための包括的なソリューションです。

PDFsharpは暗号化のネイティブサポートを持っていませんが、PdfSharp.Pdf.IOのようなサードパーティライブラリを使用してこの機能を実行することができます。 異なるレベルの暗号化を設定し、ユーザーまたはオーナーパスワードを作成して、印刷権限やコンテンツ抽出などの文書操作に関する権限を定義することができます。

コード例の比較の概要

価格設定とライセンス:IronPDF対PDFsharp

IronPDFの価格とライセンス

IronPDF ライセンスの購入には異なるレベルと追加機能があります。 開発者は、また、購入することができます アイアンスイート すべてのIronSoftwareの製品にアクセスできることを、2つの価格で提供します。 ライセンスを購入する準備ができていない場合、IronPDF は 無料試用 30日間持続する。

  • 永久ライセンス: チームの規模、プロジェクトのニーズ、拠点の数に応じたさまざまな永久ライセンスを提供しています。 各ライセンスタイプにはメールサポートが含まれています。
  • Lite License: このライセンスは$749で、1人の開発者、1つの場所、1つのプロジェクトをサポートします。
  • Plus License: 3人の開発者、3つの場所、および3つのプロジェクトをサポートし、Lite Licenseからの次のステップアップです。価格は$1,499です。Plus Licenseには基本的なメールサポートに加えて、チャットサポートと電話サポートが含まれています。
  • Professional License: このライセンスはより大規模なチームに適しており、10人の開発者、10か所の拠点、および10のプロジェクトをサポートします。価格は$2,999です。前のティアと同じ連絡サポートチャンネルを提供しますが、画面共有サポートも提供します。
  • ロイヤリティフリーの再配布: IronPDFのライセンスには、追加料金$1,999でロイヤリティフリーの再配布カバレッジも含まれています。
  • 継続的な製品サポート: IronPDFは、$999/年または一度の購入で$1,999の5年間のカバレッジで、継続的な製品更新、セキュリティ機能のアップグレード、エンジニアリングチームからのサポートへのアクセスを提供します。

  • IronSuite:1,498ドルで、IronPDF、IronOCR、IronWord、IronXL、IronBarcode、IronQR、IronZIP、IronPrint、およびIronWebScraperを含むすべてのIron Software製品にアクセスできます。

PDFsharpライセンス

PDFsharpはオープンソースのライブラリで、無料で使用できます。 しかし、これはIronPDFなどの競合他社が提供する高度で有能な機能に比べて、機能が少ないという代償を伴います。

ドキュメントとサポート:IronPDF vs. PDFsharp

IronPDFは、開発者が簡単に統合して機能を利用できるように、広範なドキュメントとサポートオプションを提供しています。

IronPDF (アイアンPDF)

  • 包括的なドキュメント:すべての機能を網羅した分かりやすいドキュメント。
  • 24/5 サポート: エンジニアによるサポートが利用可能です。
  • ビデオチュートリアル:ステップバイステップのビデオガイドがYouTubeで利用できます。
  • コミュニティフォーラム: 追加サポートのための積極的なコミュニティ。

  • 定期的な更新: 最新機能とセキュリティパッチを確保するための月次製品アップデート。

PDFsharp

  • ドキュメント: 基本的なドキュメントはウェブサイトで利用できます。
  • フォーラム: フォーラムを通じたコミュニティ主導のサポート。

  • サポート: 商業サポートオプションはありませんが、問題を報告するためのリポジトリがあります

    IronPDF のドキュメントとサポートの詳細については、訪問してください IronPDF ドキュメント および IronSoftware YouTubeチャネル.

結論

結論として、.NET環境でPDFドキュメント管理のためにIronPDFとPDFsharpのどちらを選ぶかについては、開発者は自身の特定のニーズとプロジェクト要件を考慮すべきです。 IronPDFは、HTMLからPDFへの変換、暗号化機能、およびさまざまな.NETプラットフォームと開発環境に対する強力なサポートを含む豊富な機能セットで優れています。 それは、包括的なドキュメント、複数のサポートチャネル、柔軟なライセンスオプションを提供しており、コストはかかりますが、NuGet パッケージ マネージャーを使用してプロジェクトに簡単にインストールできます。

一方で、オープンソースライブラリであるPDFsharpは無料で使用できますが、HTMLをPDFに変換するネイティブサポートやPDF暗号化といった高度な機能が不足しています。 追加のライブラリが必要になる場合があり、商業サポートオプションがないため、基本的なPDF操作タスクに主に適しています。

< 以前
スパイアPDF C# HTMLからPDFへのチュートリアル&ライブラリ比較
次へ >
Accusoft Prizmdoc PDF Viewer チュートリアルおよび比較

準備はできましたか? バージョン: 2024.9 新発売

無料のNuGetダウンロード 総ダウンロード数: 10,659,073 View Licenses >