Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
When it comes to managing PDF documents in .NET, developers have a variety of libraries to choose from, each offering unique features and capabilities. Among these, IronPDF and PDFsharp stand out as prominent options, catering to different needs and preferences.
In this article, we will be taking a closer look at the various features these libraries have to offer, along with their respective support, pricing, documentation and compatibility.
A powerful PDF library for .NET, IronPDF enables developers to create, edit, and extract PDF content easily. Users can use IronPDF to convert various formats, such as HTML, ASPX, MVC, and images, into PDF documents. IronPDF has a number of features, such as text editing, image manipulation and metadata changes, watermarking, and encrypting PDF files, among others. It is known to have an easy-to-use interface along with an impressive set of features that make it easier for the developer to work with PDF documents.
PDFsharp is a .NET-based open-source library that focuses on the dynamic generation of PDF documents. This product is implemented entirely in C# which supports drawing text, graphics and images. It also allows for modification operations like merging or splitting existing PDF files. PDFsharp is good for anyone looking for a barebones library for manipulating simple pdf files rather than something with many additional features.
IronPDF and PDFsharp both operate within the .NET environment, PDFsharp, beginning from version 6.1, has support for .NET Framework 4.7.2 or higher, .NET Standard 2.0 and .NET 6 or higher versions and can operate on .NET compatible platforms such as Linux and macOS, as well as Windows.
IronPDF supports the latest platform compatibility with various .NET versions, allowing developers to work in app environments such as Windows, Linux, Mac, Azure, Docker, and AWS, thus ensuring universal compatibility with many operating systems and development environments.
.NET versions:
(C#, VB.NET, F#)
.NET Core (8, 7, 6, 5, and 3.1+)
.NET Standard (2.0+)
.NET Project Types: Works with project types such as Blazor, MAUI, WPF, Console Apps, and more
App environments: IronPDF works in app environments including Windows, Linux, Mac, Docker, Azure, and AWS
.NET versions:
.NET Framework (4.7.2+)
.NET Standard (2.0+)
.NET Project Types: Can work with project types and technologies such as Blazor, MAUI, and ASP.NET
IronPDF gives a variety of functions for working with PDF files, such as generating, modifying and extracting content from PDFs, converting HTML, ASPX, MVC and images into PDF formats and editing text, images and metadata; apply a watermark to your PDF pages or encrypt the PDF file.
On the other hand, PDFsharp’s focus is on creating and manipulating PFD documents; it allows you to draw text lines or paragraphs on the page or insert graphics like rectangles and circles onto pages.
HTML to PDF Conversion: IronPDF supports modern web standards (CSS3, HTML5, JavaScript), which allows for high-fidelity PDF document creation.
PDF Encryption: Users can make use of IronPDF's strong encryption tools to encrypt and decrypt PDF files, adding an extra layer of security to their PDF files.
PDF Editing: The IronPDF library includes features for merging, splitting, formatting, and modifying existing PDF files.
Digital signatures for PDF files: IronPDF lets users digitally sign their PDFs.
Watermarking: Easily apply text and image watermarks to PDF files; take advantage of its use of HTML/CSS to gain full control over the process.
Create PDFs: PDFsharp can create and generate PDF files from any .NET languages
PDF manipulation: Modify, merge, and split PDFs
Draw graphics on your PDF file: PDFsharp offers the ability to draw shapes, lines, and images on your PDF document
In various workplaces and environments, converting HTML to PDF is a simple yet necessary task; the comparison between IronPDF and PDFsharp in this process is illustrated in the code examples below.
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")
PDFsharp:
PDFsharp, on its own, cannot handle HTML to PDF conversion; instead, it requires the HtmlRenderer.PdfSharp library to carry out this task. This HTML renderer can handle the HTML to PDF conversion using static rendering code.
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
IronPDF offers a convenient and simple way of turning HTML code, HTML snippets or HTML templates into PDF format, as well as allowing users to have plenty of control. Modern web standards are well supported by IronPDF, which can create PDF files that are true to the source web page.
On the other hand, PDFsharp HTML to PDF conversion is not currently supported, nor is any ability to parse HTML files; instead, the HtmlRenderer.PdfSharp library can be used alongside PDFsharp in order to complete this task.
At times, users may want to redact some portions of their PDF files, especially when working with private or sensitive information.
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")
PDFsharp:
PDFsharp does not currently offer any built-in functionality for redacting PDF content; however, as redaction involves permanently removing or hiding sensitive information, you could attempt to achieve similar results by using PDFsharp's graphics drawing tools to manually draw over the content you wish to redact. Here's an example of how this could be achieved:
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
When it comes to redacting content in PDF files, IronPDF provides a straightforward method for redacting text directly from PDF documents. Users can easily specify the text to be redacted across all pages, and its intuitive and concise API allows for the task to be done quickly and efficiently.
PDFsharp, on the other hand, does not currently support built-in redaction features. However, users can leverage its graphics drawing capabilities to manually overlay content for redaction, although this approach requires more manual intervention and customization.
If you have a need to sign PDF documents digitally, it can be very time-consuming. One way to save some of that time is to do it programmatically. In the code examples below, we will compare how document signing works between IronPDF and 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")
PDFsharp:
PDFsharp does not have built-in support for digitally signing PDF files, instead relying on external libraries such as iTextSharp in order to complete this task.
Digitally signing PDF documents programmatically can greatly simplify workflows. IronPDF has inbuilt support for digital signatures that makes the process straightforward and simple, needing only a few lines of code to complete the task. However, PDFsharp does not come with built-in digital signature capabilities so one would need third party libraries such as iTextSharp which complicates implementation further.
When dealing with private documents, copyright protection, branding or any other task that involves sensitive records; the ability to apply and personalize watermarks on PDF files can be very useful. In this article we compare IronPDF and PDFsharp when it comes to adding watermarks on a PDF document.
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")
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")
Adding watermarks to PDF documents is crucial for tasks involving privacy, copyright protection, and branding. IronPDF offers a straightforward API that allows users to efficiently apply custom watermarks using HTML/CSS, providing flexibility and ease of implementation while also giving users plenty of control over the process. On the other hand, PDFsharp requires more manual handling, utilizing graphics and text drawing methods to overlay watermarks onto PDF pages.
Converting different file types to PDF can be crucial in creating PDF files. For this instance, we will concentrate on DOCX file type and compare how IronPDF and PDFsharp work to achieve this task.
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")
PDFsharp:
PDFsharp currently does not support the direct conversion of DOCX to PDF file format. Instead, if users wish to conduct this task, they would have to make use of external libraries such as DocX.
When it comes to DOCX to PDF conversion, IronPDF provides a simple and concise approach to this task, with direct support for DOCX to PDF conversion through its DocxToPdfRenderer. This allows for seamless rendering and saving of the resulting PDF.
PDFsharp does not natively support DOCX to PDF conversion; users must rely on external libraries like DocX to achieve this functionality.
Sometimes, like when applying watermarks, PDF pages may need to be stamped with something on them. In this section, we shall examine the stamping capabilities of IronPDF against PDFsharp on a PDF document.
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")
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")
IronPDF enables users to add text and images to PDF documents with ease, all while keeping the process straightforward and simple. It gives the user complete power over all aspects of the process, particularly for those familiar with HTML/CSS.
On the other hand, PDFsharp requires more manual handling with its XGraphics object, where text and images are stamped directly onto each page using specific coordinates and graphical parameters.
Whether it is at an office, a school or a library, encrypting and decrypting PDF documents forms part of many work settings. Therefore, having a program that can carry out this function without complications can be essential. This section will compare how IronPDF and PDFsharp handle PDF encryption tasks.
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")
PDFsharp:
PDFsharp on its own does not have built-in support for PDF encryption. However, users can install the PdfSharp.Pdf.IO library to help carry out this task.
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")
IronPDF is a robust tool with strong encryption features that lets you easily encrypt PDFs and manage security settings like read-only access, copy-paste restriction and print permission. You can also add password protection to the encrypted files and customize metadata; in short, IronPDF is an all-inclusive solution for secure PDF management.
PDFsharp does not have any native support for encryption but it can use third-party libraries such as PdfSharp.Pdf.IO to perform this function. You are able to set different levels of encryption, create user or owner passwords and define permissions on printing rights or content extraction among other document operations.
IronPDF has different levels and additional features for purchasing a license. Developers can also buy IronSuite which, gives you access to all of IronSoftware’s products at the price of two. If you’re not ready to buy a license, IronPDF provides a free trial that lasts 30 days.
Perpetual licenses: Offers a range of perpetual licenses depending on the size of your team, your project needs, and the number of locations. Each license type comes with email support.
Lite License: This license costs $749 and supports one developer, one location, and one project.
Plus License: Supporting three developers, three locations, and three projects, this is the next step up from the lite license and costs $1,499. The Plus license offers chat support and phone support in addition to basic email support.
Professional License: This license is suitable for larger teams, supporting ten developers, ten locations, and ten projects for $2,999. It offers the same contact support channels as the previous tiers but also offers screen-sharing support.
Royalty-free redistribution: IronPDF's licensing also offers royalty-free redistribution coverage for an extra $1,999
Uninterrupted product support: IronPDF offers access to ongoing product updates, security feature upgrades, and support from their engineering team for either $999/year or a one-time purchase of $1,999 for a 5-year coverage.
PDFsharp is an open-source library and is free to use. However, this comes with the cost of having less advanced and capable features than competitors such as IronPDF offer.
IronPDF provides extensive documentation and support options, ensuring developers can easily integrate and utilize its features.
Comprehensive Documentation: Extensive and user-friendly documentation covering all features.
24/5 Support: Active engineer support is available.
Video Tutorials: Step-by-step video guides are available on YouTube.
Community Forum: Engaged community for additional support.
Documentation: Basic documentation is available on the website.
Forums: Community-driven support through forums.
For more details on IronPDF documentation and support, visit IronPDF Documentation and the IronSoftware YouTube Channel.
In conclusion, when choosing between IronPDF and PDFsharp for PDF document management in .NET environments, developers should consider their specific needs and project requirements. IronPDF excels with its extensive feature set which includes HTML to PDF conversion, encryption capabilities, and robust support for various .NET platforms and development environments. It offers comprehensive documentation, multiple support channels, and flexible licensing options, albeit at a cost, and can be easily installed into your project using the NuGet Package Manager.
On the other hand, PDFsharp, as an open-source library, is free to use but lacks advanced features such as native support for HTML to PDF conversion and PDF encryption. It may require additional libraries and lacks commercial support options, making it suitable primarily for basic PDF manipulation tasks.
You can try the 30-day free trial to check out their available features.
9 .NET API products for your office documents