Przejdź do treści stopki
PORóWNANIA PRODUKTóW

Poznaj najlepsze alternatywy dla PDFsharp do dodawania znaku wodnego do PDF

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 betweenIronPDFand PDFsharp for adding watermarks to existing PDFs, offering insights into their functionalities, implementation processes, and customization capabilities.

The comparison covers both libraries' watermarking APIs with working code examples, so you can assess which fits your project's requirements.

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, and are closely related to text and image stamps used for document annotation.

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.

What AreIronPDFand PDFsharp?

IronPDF

IronPDF is a premium, feature-rich .NET library designed to streamline PDF handling, from creating PDFs from scratch to advanced manipulation tasks. 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#. If you are currently using PDFsharp and considering a switch, the PDFsharp toIronPDFmigration guide walks through the transition process. It offers fine-grained control over drawing operations, though watermarking involves more manual implementation than IronPDF's abstracted approach.

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).
  • Does not include built-in high-level watermarking functions; developers implement features like opacity and rotation directly through the drawing API.

Here is a quick side-by-side summary of how the two libraries compare for watermarking tasks:

Funkcja IronPDF PDFsharp
Text Watermark Built-in ApplyWatermark method Manual drawing via XGraphics API
Image Watermark HTML/CSS <img> tag support DrawImage with manual positioning
Opacity Control Parameter on ApplyWatermark Requires custom brush/alpha handling
Rotation Parameter on ApplyWatermark Manual RotateTransform call
Watermark Styling Full HTML/CSS support Font and brush configuration
.NET Compatibility .NET 6+, Core, Framework .NET Framework, Core (via PDFSharpCore)
Licencjonowanie Commercial (perpetual option) Open-source (MIT)

IronPDF's [free 30-day trial](trial-license includes the full watermarking API used in the examples below.

Adding a Watermark with IronPDF

IronPDF provides a high-level API that enables developers to apply watermarks in just a few lines of code, without manual coordinate calculations or graphics pipeline setup. Because IronPDF's watermark tool accepts HTML/CSS strings — leveraging the same Chromium-based HTML rendering engine used across the library — you get full control over styling, positioning, and appearance using familiar web markup.

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, similar to how you would use HTML to create a PDF from scratch. 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 via IronPDF's rendering options parameters.

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 draws a watermark on each page through explicit coordinate-based positioning. While it produces a similar output to theIronPDFexample, PDFsharp's approach involves more code — IronPDF's text watermark requires roughly 4 active lines versus PDFsharp's 10, since PDFsharp delegates layout decisions (translation, rotation, font selection) to the developer rather than abstracting them.

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 at a fixed position and size. Opacity handling is outside PDFsharp's single-call API surface — developers who need transparency control manage it through the XGraphics pipeline directly. As with the text watermark example, PDFsharp gives you granular control over rendering at the cost of additional setup compared to IronPDF's higher-level watermarking API.

How DoIronPDFand PDFsharp Compare for Watermarking?

Łatwość użytkowania

  • 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.

Wydajność

  • IronPDF: Ships as a single NuGet package with watermark operations that handle opacity, rotation, and positioning in one method call, reducing per-page processing overhead when watermarking multi-page documents. W przypadku procesów na dużą skalę zapoznaj się z przewodnikiem po optymalizacji wydajności IronPDF.
  • PDFSharp: Lekki, o niewielkim śladzie zależności. W przypadku złożonych zadań związanych z dodawaniem znaków wodnych, wymagających wielu przekształceń na stronie, programiści mogą potrzebować profilowania i optymalizacji logiki rysowania, ponieważ PDFsharp nie przetwarza tych operacji w trybie wsadowym ani nie buforuje ich wewnętrznie.

Opcje dostosowywania

  • IronPDF: Wbudowana obsługa dostosowywania krycia, obrotu, pozycjonowania i rozmiaru czcionki. Użytkownicy mogą łatwo dostosowywać ustawienia bez zagłębiania się w skomplikowaną logikę renderowania.
  • PDFSharp: Wymaga dodatkowego kodowania w celu obsługi krycia, efektów przezroczystości i transformacji. While powerful, it demands a higher level of customization from the developer, including using the var format for specific rendering tasks.

Kompatybilność

  • IronPDF: W pełni kompatybilny z .NET 6+, .NET Core i .NET Framework, dzięki czemu nadaje się do nowoczesnych i starszych aplikacji.
  • PDFSharp: Obsługuje .NET Framework i .NET Core (poprzez PDFSharpCore). Niektóre nowsze funkcje frameworka mogą wykraczać poza jego obecny zakres, w zależności od wybranego portu społecznościowego.

Licencjonowanie and Cost

  • IronPDF: produkt komercyjny, który wymaga płatnej licencji, ale obejmuje opcje Licencji wieczystej, obsługę klienta i ciągłe aktualizacje.
  • PDFSharp: oprogramowanie typu open source i darmowe, co czyni je opłacalnym rozwiązaniem dla programistów, którzy preferują model licencyjny bez ograniczeń, ale są gotowi samodzielnie zajmować się wsparciem technicznym i aktualizacjami.

Oprócz kosztów licencji, całkowity koszt projektu obejmuje godziny pracy programistów poświęcone na ręczne pozycjonowanie oparte na współrzędnych, niestandardową logikę krycia i obrotu oraz kod rysowania na stronie, któryIronPDFobsługuje za pomocą jednego wywołania metody. Dla zespołów oceniających koszty w perspektywie wieloletniego cyklu życia projektu, te godziny poświęcone na wdrożenie i utrzymanie często przewyższają różnicę między licencjami open source a komercyjnymi.

Którą bibliotekę wybrać?

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

PDFsharp zapewnia solidną kontrolę rysowania na niskim poziomie oraz licencję open source — co stanowi prawdziwą zaletę dla zespołów o ograniczonym budżecie i zdolnościach programistycznych pozwalających na tworzenie logiki znakowania wodnego od podstaw. Dla zespołów, które potrzebują wbudowanych funkcji pozycjonowania znaków wodnych, krycia, obracania oraz stylizacji opartej na HTML/CSS jako operacji najwyższej klasy, IronPDF oferuje bardziej kompleksowy interfejs API, który skraca czas wdrożenia. Ostatecznie najlepszy wybór zależy od wymagań projektu, wiedzy programistycznej i dostępnych zasobów.

WypróbujIronPDFsamodzielnie, pobierając bezpłatną wersję próbną i odkrywając, jak już dziś może ona przenieść Twoje projekty C# PDF na wyższy poziom!

Zwróć uwagęPDFsharp jest zastrzeżonym znakiem towarowym odpowiedniego właściciela. Ta strona nie jest powiązana z PDFsharp, nie jest przez niego promowana ani sponsorowana. Wszystkie nazwy produktów, logo i marki są własnością ich odpowiednich właścicieli. Porównania mają charakter wyłącznie informacyjny i odzwierciedlają informacje dostępne publicznie w momencie pisania.

Często Zadawane Pytania

Jak dodać znak wodny do pliku PDF za pomocą biblioteki .NET?

Możesz dodać znak wodny do pliku PDF za pomocą IronPDF, korzystając z jego prostego API, które obsługuje zarówno znaki wodne tekstowe, jak i graficzne z opcjami dostosowywania, takimi jak krycie i obrót.

Jakie są zalety korzystania z wysokiej jakości biblioteki .NET do tworzenia znaków wodnych w plikach PDF?

Wysokiej klasy biblioteka .NET do obsługi plików PDF, taka jak IronPDF, oferuje zaawansowane funkcje ułatwiające dodawanie znaków wodnych, kompatybilność z nowoczesnymi frameworkami .NET oraz dodatkowe funkcje, takie jak adnotacje w plikach PDF i konwersja HTML do PDF.

Dlaczego znak wodny jest ważny w dokumentach PDF?

Znak wodny jest ważny dla bezpieczeństwa dokumentów, budowania marki i kontroli wersji. Pomaga zapobiegać nieautoryzowanemu powielaniu, zapewnia spójność marki i oznacza dokumenty jako poufne.

Jakie są różnice między IronPDF a PDFsharp w zakresie dodawania znaków wodnych do plików PDF?

IronPDF zapewnia bardziej intuicyjny interfejs API, umożliwiający łatwe dodawanie znaków wodnych przy minimalnym nakładzie kodu, podczas gdy PDFsharp wymaga większego nakładu pracy ręcznej i dodatkowego kodowania w celu przeprowadzenia transformacji i ustawienia krycia.

W jaki sposób IronPDF usprawnia obsługę plików PDF w porównaniu z opcjami open source?

IronPDF oferuje wbudowane funkcje wysokiego poziomu, ułatwiające wykonywanie operacji na plikach PDF, takich jak dodawanie znaków wodnych, adnotacji i konwersji, które w opcjach open source, takich jak PDFsharp, wymagałyby bardziej złożonego kodowania.

Jakie rodzaje znaków wodnych można dodawać do plików PDF za pomocą bibliotek .NET?

Dzięki bibliotekom takim jak IronPDF można dodawać znaki wodne tekstowe, graficzne i przezroczyste, z opcjami dostosowania położenia, krycia i obrotu.

Czy IronPDF nadaje się do obsługi dużych dokumentów PDF?

Tak, IronPDF jest zoptymalizowany pod kątem szybkiego przetwarzania i może sprawnie obsługiwać duże dokumenty PDF bez utraty wydajności.

Co należy wziąć pod uwagę przy wyborze między biblioteką PDF dla platformy .NET typu premium a biblioteką typu open source?

Należy wziąć pod uwagę łatwość użytkowania, dostępne funkcje, kompatybilność, wydajność i wsparcie techniczne. Biblioteka premium, taka jak IronPDF, oferuje rozbudowane funkcje i wsparcie techniczne, podczas gdy biblioteka open source, taka jak PDFsharp, jest bezpłatna, ale wymaga bardziej złożonego kodowania i nie posiada oficjalnego wsparcia.

Czy mogę używać IronPDF z .NET Core?

Tak, IronPDF jest kompatybilny z .NET 6+, .NET Core i .NET Framework, co sprawia, że jest wszechstronny w różnych środowiskach programistycznych.

Jakie dodatkowe funkcje oferuje IronPDF poza dodawaniem znaków wodnych?

Oprócz znaków wodnych IronPDF obsługuje adnotacje w plikach PDF, konwersję HTML do PDF, podpisy cyfrowe i wiele innych funkcji, oferując kompleksowe możliwości edycji plików PDF.

Curtis Chau
Autor tekstów technicznych

Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podrę...

Czytaj więcej

Zespol wsparcia Iron

Jestesmy online 24 godziny, 5 dni w tygodniu.
Czat
Email
Zadzwon do mnie