Link Search Menu Expand Document

Add Image Stamp in PDF - C#

PDF Extractor SDK sample in C# demonstrating ‘Add Image Stamp in PDF’

Program.cs
using System.Diagnostics;
using System.Drawing;
using Bytescout.PDFExtractor;

namespace AddImageStampInPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputFile = @".\Invoice.pdf";
            string outputFile = @".\Invoice_Stamped.pdf";
            string stampImageFile = @".\stamp_image.png";

            using (Stamper stamper = new Stamper("demo", "demo"))
            {
                // Optionally make the image background transparent
                // stamper.MakeStampImageTransparent = true;

                using (Image image = Image.FromFile(stampImageFile))
                {
                    // Get image size in PDF units
                    SizeF imageSizeInPoints = stamper.GetImageSizeInPoints(image);

                    RectangleF rectangle = new RectangleF(440, 370, imageSizeInPoints.Width / 3, imageSizeInPoints.Height / 3);

                    stamper.Stamp(inputFile, outputFile, image, rectangle, 0, -1);
                }
            }

            // Open first output file in default associated application (for demo purposes)
            ProcessStartInfo processStartInfo = new ProcessStartInfo(outputFile);
            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
    }
}

Download Source Code (.zip)

Return to the previous page Explore PDF Extractor SDK


Copyright © 2016 - 2021 ByteScout