Zum Fußzeileninhalt springen
PRODUKTVERGLEICHE

Entdecken Sie die besten Alternativen zum Hinzufügen von Wasserzeichen zu PDF mit PDFsharp

Adding watermarks to PDFs is a common requirement for document security, branding, and version control. Whether marking documents as confidential, branding official reports, or preventing unauthorized reproduction, watermarking is an essential feature.

In C#, developers have multiple libraries to choose from, with IronPDF and PDFSharp being two of the most popular options. However, their approaches, ease of use, performance, and licensing structures differ significantly. This article provides a detailed comparison between IronPDF and PDFsharp for adding watermarks to existing PDFs, offering insights into their functionalities, implementation processes, and customization capabilities.

By the end of this article, you will have a clear understanding of which library best suits your project’s needs based on ease of use, performance, and feature availability.

Understanding PDF Watermarking

What is a Watermark?

A watermark is a graphical or textual overlay on a document that serves as an identifier, deterrent, or branding element. Watermarks can be visible or invisible, depending on their purpose.

Types of Watermarks

  • Text Watermark – Typically a semi-transparent overlay with a message like "CONFIDENTIAL" or "DRAFT."
  • Image Watermark – A logo, emblem, or graphic embedded into the document.
  • Transparent Watermark – A subtle branding mark that doesn’t obstruct the document’s readability.
  • Stamped Watermark – A more prominent, bold marking that ensures visibility.

Common Use Cases

  • Security & Protection – Prevent unauthorized duplication by marking documents as proprietary.
  • Branding – Add company logos or signatures to maintain brand consistency across documents.
  • Version Control – Label drafts, final versions, or document revisions.

Overview of IronPDF and PDFsharp

IronPDF

IronPDF is a premium, feature-rich .NET library designed to streamline PDF handling. It is especially useful for developers looking for easy implementation of PDF manipulation tasks, including watermarking.

Key Features:

  • Simple and intuitive API requiring minimal code.
  • Supports text and image watermarks with customization options.
  • Offers opacity control, positioning, and rotation for precise placement.
  • Compatible with .NET 6+, .NET Core, and .NET Framework.
  • Available with a perpetual licensing model for long-term use.
  • Additional capabilities include PDF annotations, HTML-to-PDF conversion, and digital signatures.

PDFsharp

PDFsharp is an open-source library that allows developers to create, edit, and manipulate PDFs in C#. While it is highly flexible, watermarking requires more manual effort compared to IronPDF.

Key Features:

  • Free and open-source, making it cost-effective for budget-conscious projects.
  • Provides low-level control over PDF drawing operations, including both outlined graphical paths and transparent graphical paths.
  • Supports both text and image watermarks but requires additional code for transformations.
  • Works with .NET Framework and .NET Core (via PDFSharpCore).
  • Lacks built-in high-level watermarking functions, requiring developers to manually implement features like opacity and rotation.

Adding a Watermark with IronPDF

IronPDF provides a simple API that enables developers to apply watermarks efficiently with just a few lines of code, making it easy to streamline your PDF watermarking tasks efficiently, without any complex or manual setups. IronPDF's watermark tool can use HTML/CSS strings for the watermark, as you will see below, giving you full control over how your watermark will appear.

Text Watermark Example

using IronPdf;

const string filename = "existing.pdf";
// Load the existing PDF file
PdfDocument pdf = PdfDocument.FromFile(filename);

// Create a simple HTML-based watermark
string watermark = "<h1 style='color:red'>Confidential!</h1>";

// Apply the watermark to the PDF
pdf.ApplyWatermark(watermark);

// Save the updated document with the applied watermark
pdf.SaveAs("watermarked.pdf");
using IronPdf;

const string filename = "existing.pdf";
// Load the existing PDF file
PdfDocument pdf = PdfDocument.FromFile(filename);

// Create a simple HTML-based watermark
string watermark = "<h1 style='color:red'>Confidential!</h1>";

// Apply the watermark to the PDF
pdf.ApplyWatermark(watermark);

// Save the updated document with the applied watermark
pdf.SaveAs("watermarked.pdf");
Imports IronPdf

Private Const filename As String = "existing.pdf"
' Load the existing PDF file
Private pdf As PdfDocument = PdfDocument.FromFile(filename)

' Create a simple HTML-based watermark
Private watermark As String = "<h1 style='color:red'>Confidential!</h1>"

' Apply the watermark to the PDF
pdf.ApplyWatermark(watermark)

' Save the updated document with the applied watermark
pdf.SaveAs("watermarked.pdf")
$vbLabelText   $csharpLabel

Explore the Best Alternatives for PDFsharp Add Watermark to PDF: Figure 3 - Text watermark output

In this code example, we see just how easy it is to apply a watermark to your existing PDF files with IronPDF. Here, we load the existing PDF using the FromFile method. Then, we create a simple string formatted as an HTML element as the watermark and apply it to the PDF using ApplyWatermark. As shown in the output image, this has added a simple text string "Confidential" as a watermark on our PDF.

Image Watermark Example

using IronPdf;

// Load the PDF document
PdfDocument pdf = PdfDocument.FromFile("existing.pdf");

// Create an HTML-based watermark containing the image
string watermark = "<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>";

// Apply the watermark to the PDF with rotation and opacity
pdf.ApplyWatermark(watermark, rotation: 45, opacity: 80);

// Save the watermarked document
pdf.SaveAs("watermarked.pdf");
using IronPdf;

// Load the PDF document
PdfDocument pdf = PdfDocument.FromFile("existing.pdf");

// Create an HTML-based watermark containing the image
string watermark = "<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>";

// Apply the watermark to the PDF with rotation and opacity
pdf.ApplyWatermark(watermark, rotation: 45, opacity: 80);

// Save the watermarked document
pdf.SaveAs("watermarked.pdf");
Imports IronPdf

' Load the PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("existing.pdf")

' Create an HTML-based watermark containing the image
Private watermark As String = "<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>"

' Apply the watermark to the PDF with rotation and opacity
pdf.ApplyWatermark(watermark, rotation:= 45, opacity:= 80)

' Save the watermarked document
pdf.SaveAs("watermarked.pdf")
$vbLabelText   $csharpLabel

Explore the Best Alternatives for PDFsharp Add Watermark to PDF: Figure 4

Adding an image as a watermark is just as easy as adding text, as they both use the same method. Just like in the text example, we create a new watermark string variable containing the HTML image tag pointing to the image URL and apply it. This time, we include customized rotation and opacity transformations.

This approach overlays an image watermark at a specified position, allowing for custom placement and transparency.

Adding a Watermark with PDFsharp

PDFsharp requires developers to manually render text and images using its GDI+ drawing API. To watermark an existing PDF file, create an XGraphics object for drawing and apply the desired content.

Text Watermark Example

using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

const string filename = "existing.pdf";
// Open the PDF document in modify mode
var document = PdfReader.Open(filename, PdfDocumentOpenMode.Modify);

foreach (var page in document.Pages)
{
    // Create an XGraphics object for drawing
    var gfx = XGraphics.FromPdfPage(page);

    // Move the origin to the center of the page for rotation purposes
    gfx.TranslateTransform(page.Width / 2, page.Height / 2);

    // Rotate for diagonal watermark placement
    gfx.RotateTransform(Math.Atan(page.Height / page.Width));

    // Define font and brush for drawing the watermark text
    var font = new XFont("Arial", 40);
    var brush = new XSolidBrush(XColor.FromArgb(128, XColors.Red));  // Semi-transparent red

    // Draw the watermark text centered on the page
    gfx.DrawString("WATERMARK", font, brush, new XPoint(0, 0));
}

// Save modified document
document.Save("watermarked.pdf");
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

const string filename = "existing.pdf";
// Open the PDF document in modify mode
var document = PdfReader.Open(filename, PdfDocumentOpenMode.Modify);

foreach (var page in document.Pages)
{
    // Create an XGraphics object for drawing
    var gfx = XGraphics.FromPdfPage(page);

    // Move the origin to the center of the page for rotation purposes
    gfx.TranslateTransform(page.Width / 2, page.Height / 2);

    // Rotate for diagonal watermark placement
    gfx.RotateTransform(Math.Atan(page.Height / page.Width));

    // Define font and brush for drawing the watermark text
    var font = new XFont("Arial", 40);
    var brush = new XSolidBrush(XColor.FromArgb(128, XColors.Red));  // Semi-transparent red

    // Draw the watermark text centered on the page
    gfx.DrawString("WATERMARK", font, brush, new XPoint(0, 0));
}

// Save modified document
document.Save("watermarked.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf.IO

Private Const filename As String = "existing.pdf"
' Open the PDF document in modify mode
Private document = PdfReader.Open(filename, PdfDocumentOpenMode.Modify)

For Each page In document.Pages
	' Create an XGraphics object for drawing
	Dim gfx = XGraphics.FromPdfPage(page)

	' Move the origin to the center of the page for rotation purposes
	gfx.TranslateTransform(page.Width \ 2, page.Height \ 2)

	' Rotate for diagonal watermark placement
	gfx.RotateTransform(Math.Atan(page.Height \ page.Width))

	' Define font and brush for drawing the watermark text
	Dim font = New XFont("Arial", 40)
	Dim brush = New XSolidBrush(XColor.FromArgb(128, XColors.Red)) ' Semi-transparent red

	' Draw the watermark text centered on the page
	gfx.DrawString("WATERMARK", font, brush, New XPoint(0, 0))
Next page

' Save modified document
document.Save("watermarked.pdf")
$vbLabelText   $csharpLabel

This implementation manually draws a watermark on each page, requiring precise positioning and customization. While it's capable of handling the task with a similar output to the IronPDF example, PDFsharp requires more code and a more complex method to handle applying text watermarks to existing content or new PDF files.

Image Watermark Example

using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

// Open the existing PDF document in modify mode
var document = PdfReader.Open("sample.pdf", PdfDocumentOpenMode.Modify);

// Load the watermark image
XImage watermark = XImage.FromFile("watermark.png");

foreach (var page in document.Pages)
{
    // Create a graphics object from the page
    XGraphics gfx = XGraphics.FromPdfPage(page);

    // Draw the image watermark at the specified position and size
    gfx.DrawImage(watermark, 50, 100, watermark.PixelWidth / 2, watermark.PixelHeight / 2);
}

// Save the modified PDF document
document.Save("watermarked.pdf");
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

// Open the existing PDF document in modify mode
var document = PdfReader.Open("sample.pdf", PdfDocumentOpenMode.Modify);

// Load the watermark image
XImage watermark = XImage.FromFile("watermark.png");

foreach (var page in document.Pages)
{
    // Create a graphics object from the page
    XGraphics gfx = XGraphics.FromPdfPage(page);

    // Draw the image watermark at the specified position and size
    gfx.DrawImage(watermark, 50, 100, watermark.PixelWidth / 2, watermark.PixelHeight / 2);
}

// Save the modified PDF document
document.Save("watermarked.pdf");
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf.IO

' Open the existing PDF document in modify mode
Private document = PdfReader.Open("sample.pdf", PdfDocumentOpenMode.Modify)

' Load the watermark image
Private watermark As XImage = XImage.FromFile("watermark.png")

For Each page In document.Pages
	' Create a graphics object from the page
	Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

	' Draw the image watermark at the specified position and size
'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(watermark, 50, 100, watermark.PixelWidth / 2, watermark.PixelHeight / 2)
Next page

' Save the modified PDF document
document.Save("watermarked.pdf")
$vbLabelText   $csharpLabel

Explore the Best Alternatives for PDFsharp Add Watermark to PDF: Figure 6

This method places an image watermark; however, unlike IronPDF, opacity handling must be managed separately. Like the text watermark example, applying an image-based watermark onto an existing PDF with PDFsharp requires a more elaborate and intricate setup compared to IronPDF's streamlined watermarking API.

Comparing IronPDF and PDFsharp for Watermarking

Ease of Use

  • IronPDF: Provides high-level functions that simplify watermarking with minimal code. It abstracts complex operations, making it ideal for developers who need a quick and efficient solution.
  • PDFSharp: Requires manual implementation using the graphics API, which increases complexity and development time. It is better suited for developers who need fine-grained control over rendering but are comfortable with additional coding.

Performance

  • IronPDF: Optimized for high-speed PDF processing, capable of handling large documents efficiently without significant performance degradation.
  • PDFSharp: While lightweight, it may require additional optimizations for handling large PDFs. Complex watermarking tasks with multiple transformations can lead to slower performance compared to IronPDF.

Customization Options

  • IronPDF: Built-in support for opacity, rotation, positioning, and font size customization. Users can easily tweak settings without delving into complex rendering logic.
  • PDFSharp: Requires additional coding for opacity, transparency effects, and transformation handling. While powerful, it demands a higher level of customization from the developer, including using the var format for specific rendering tasks.

Compatibility

  • IronPDF: Fully compatible with .NET 6+, .NET Core, and .NET Framework, making it suitable for modern and legacy applications.
  • PDFSharp: Supports .NET Framework and .NET Core (via PDFSharpCore), but may lack certain modern features available in newer frameworks.

Licensing and Cost

  • IronPDF: A commercial product that requires a paid license but includes perpetual licensing options, customer support, and continuous updates.
  • PDFSharp: Open-source and free to use, making it a cost-effective solution for developers who prefer an unrestricted licensing model but are willing to handle their own support and updates.

Conclusion

Explore the Best Alternatives for PDFsharp Add Watermark to PDF: Figure 7

For developers who need an easy and efficient way to watermark PDFs, IronPDF is the superior choice due to its user-friendly API and built-in features. However, if budget constraints are a concern and you don’t mind writing additional code, PDFSharp is a solid open-source alternative. Ultimately, the best choice depends on your project requirements, coding expertise, and available resources.

Try IronPDF out for yourself by downloading the free trial and exploring how it can take your C# PDF projects to the next level today!

Hinweis:PDFsharp is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by PDFsharp. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing.

Häufig gestellte Fragen

Wie kann ich ein Wasserzeichen zu einer PDF mithilfe einer .NET-Bibliothek hinzufügen?

Sie können ein Wasserzeichen zu einer PDF mit IronPDF hinzufügen, indem Sie dessen einfache API nutzen, die sowohl Text- als auch Bildwasserzeichen mit anpassbaren Optionen wie Deckkraft und Rotation unterstützt.

Was sind die Vorteile der Nutzung einer Premium .NET PDF-Bibliothek für Wasserzeichen?

Eine Premium .NET PDF-Bibliothek wie IronPDF bietet hochentwickelte Funktionen für einfaches Hinzufügen von Wasserzeichen, Kompatibilität mit modernen .NET-Frameworks und zusätzliche Funktionen wie PDF-Anmerkungen und HTML-zu-PDF-Konvertierung.

Warum ist das Hinzufügen von Wasserzeichen in PDF-Dokumenten wichtig?

Wasserzeichen sind wichtig für die Dokumentensicherheit, das Branding und die Versionskontrolle. Sie helfen unerlaubte Vervielfältigung zu verhindern, sorgen für Markenkonsistenz und kennzeichnen Dokumente als vertraulich.

Was sind die Unterschiede zwischen IronPDF und PDFsharp beim Hinzufügen von Wasserzeichen in PDFs?

IronPDF bietet eine intuitivere API für einfaches Hinzufügen von Wasserzeichen mit minimalem Codeaufwand, während PDFsharp mehr manuellen Aufwand und zusätzliche Codierung für Transformationen und Deckkraft-Einstellungen erfordert.

Wie verbessert IronPDF die PDF-Bearbeitung im Vergleich zu Open-Source-Optionen?

IronPDF bietet eingebaute hochentwickelte Funktionen, die es einfacher machen, PDF-Bearbeitungen wie Wasserzeichen, Anmerkungen und Konvertierungen durchzuführen, was bei Open-Source-Optionen wie PDFsharp komplexere Programmierung erfordern würde.

Welche Arten von Wasserzeichen können mit .NET-Bibliotheken zu PDFs hinzugefügt werden?

Mit Bibliotheken wie IronPDF können Sie Textwasserzeichen, Bildwasserzeichen und transparente Wasserzeichen hinzufügen, mit Optionen zur Anpassung hinsichtlich Positionierung, Deckkraft und Rotation.

Ist IronPDF geeignet für die Bearbeitung großer PDF-Dokumente?

Ja, IronPDF ist für Hochgeschwindigkeitsverarbeitung optimiert und kann große PDF-Dokumente effizient ohne Leistungsprobleme bearbeiten.

Was sollte ich beachten, wenn ich zwischen einer Premium- und einer Open-Source .NET PDF-Bibliothek wähle?

Berücksichtigen Sie Benutzerfreundlichkeit, verfügbare Funktionen, Kompatibilität, Leistung und Support. Eine Premium-Bibliothek wie IronPDF bietet umfangreiche Funktionen und Support, während eine Open-Source-Bibliothek wie PDFsharp kostenlos ist, aber komplexere Codierung erfordert und keinen offiziellen Support bietet.

Kann ich IronPDF mit .NET Core verwenden?

Ja, IronPDF ist kompatibel mit .NET 6+, .NET Core und .NET Framework, was es vielseitig für verschiedene Entwicklungsumgebungen macht.

Welche zusätzlichen Funktionen bietet IronPDF über das Hinzufügen von Wasserzeichen hinaus?

Neben dem Hinzufügen von Wasserzeichen unterstützt IronPDF PDF-Anmerkungen, HTML-zu-PDF-Konvertierung, digitale Signaturen und mehr, und bietet umfassende PDF-Bearbeitungsfunktionen.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen