Home

Bytescout.PDF for .NET



Bytescout.PDF library for .NET - watermarking PDF document with background logo image

Download Free Trial Buy Now More Information
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead

Watermarking existing PDF document using PNG logo image watermark

This example demonstrates how to watermark existing PDF document with PNG logo image using Bytescout.PDF library

Output watermarked PDF document watermarked using Bytescout.PDF library for .NET

Download example source code: bytescoutpdf_watermarking_pdf_documents_with_logo.zip (80 KB)

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.PDF;
using System.Diagnostics;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create main PDF Doc Engine
PDFDocEngine engine = new PDFDocEngine("", "");

// Add new document
Document document = engine.AddDocument("Document.pdf");

// Add image to PDF
uint resIndex = document.AddImage("mylogo.png", 0, ImageCompressionType.JPEG);

for (uint i = 0; i < 4; i++)
{
// Append new page to the document
Page page = document.GetPage(i);

// Create new drawing
Drawing drawing = page.AddDrawing();

// Save the current graphics state on the graphics state stack
drawing.StateStore();

// Create new graphic state
DrawingState drawingState = new DrawingState(document);

// Set fill alpha blending to 30%
drawingState.AlphaFill = 0.3f;
// Set lines alpha blending to 100%
drawingState.AlphaStroke = 1.0f;
// Set graphic state as current
drawing.SetGState(drawingState);

// Place image
drawing.PlaceImage(resIndex, 0, 0, drawing.Width, drawing.Height, 0);

// Restore previous graphics state
drawing.StateRestore();

// Closing drawing on the page
drawing.Close();
}
// Save document
document.Save("Result.pdf");

// open generated PDF document in default PDF viewer installed in Windows
Process.Start("Result.pdf");
}
}
}

Download example source code: bytescoutpdf_watermarking_pdf_documents_with_logo.zip (80 KB)

Download Free Trial Buy Now More Information
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead

"Hello, World!" quick start step-by-step tutorials:

Advanced Examples:
Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials  |  News |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement