The code below will help you to implement an C# app to add watermarks to PDF. ByteScout PDF SDK can add watermarks to PDF. It can be used from C#. ByteScout PDF SDK is the pdf library that can create, update and modify PDF files. Supports text with fonts and style selections, layers, form fields, drawing lines and objects, automatic tables, images. Can be used to create and fill pdf forms.
You will save a lot of time on writing and testing code as you may just take the C# code from ByteScout PDF SDK for add watermarks to PDF below and use it in your application. Just copy and paste the code into your C# application’s code and follow the instruction. Further enhancement of the code will make it more vigorous.
ByteScout free trial version is available for download from our website. It includes all these programming tutorials along with source code samples.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
using System.Diagnostics; using Bytescout.PDF; namespace Watermarks { /// <summary> /// This example demonstrates how add text watermark to document page. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add pages pdfDocument.Pages.Add(new Page(PaperFormat.A4)); pdfDocument.Pages.Add(new Page(PaperFormat.A4)); pdfDocument.Pages.Add(new Page(PaperFormat.A4)); // Add tiling watermark TextWatermark watermark1 = new TextWatermark("Tiling Watermark"); watermark1.WatermarkLocation = TextWatermarkLocation.Tiled; watermark1.Angle = 30; SolidBrush brush1 = new SolidBrush(new ColorRGB(0, 0, 255)); brush1.Opacity = 50; // make the brush semitransparent watermark1.Brush = brush1; pdfDocument.Watermarks.Add(watermark1); // Add autosized watermark to every page of the document TextWatermark watermark2 = new TextWatermark("Diagonal Watermark"); watermark2.WatermarkLocation = TextWatermarkLocation.DiagonalFromBottomLeftToTopRight; watermark2.Font = new Font("Times New Roman", 16); SolidBrush brush2 = new SolidBrush(new ColorRGB(255, 0, 0)); brush2.Opacity = 50; // make the brush semitransparent watermark2.Brush = brush2; watermark2.Pen = new SolidPen(new ColorRGB(255, 0, 0)); // outline pen is optional pdfDocument.Watermarks.Add(watermark2); // Add watermark of custom size and location to the first page only TextWatermark watermark3 = new TextWatermark("Simple Watermark"); watermark3.Font = new Font(StandardFonts.HelveticaBold, 24); watermark3.Brush = new SolidBrush(new ColorRGB(0, 128, 0)); watermark3.Left = 350; watermark3.Top = 800; pdfDocument.Pages[0].Watermarks.Add(watermark3); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } } }
60 Day Free Trial or Visit ByteScout PDF SDK Home Page
Explore ByteScout PDF SDK Documentation
Explore Samples
Sign Up for ByteScout PDF SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout PDF SDK Home Page
Explore ByteScout PDF SDK Documentation
Explore Samples
Sign Up for ByteScout PDF SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: