//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Drawing;usingGrapeCity.Documents.Pdf.Annotations;usingGrapeCity.Documents.Pdf.Graphics;usingSystem.Numerics;usingGCTEXT = GrapeCity.Documents.Text;usingGCDRAW = GrapeCity.Documents.Drawing; namespaceDsPdfWeb.Demos.Basics{// This sample demonstrates how to add a custom appearance stream// to an annotation using a FormXObject.// We load an existing PDF and then loop over its pages.// On each page we create a StampAnnotation and a FormXObject// which is assigned to the annotation's normal default appearance stream.// A semi-transparent PNG image representing the stamp is then drawn// on the FormXObject's Graphics using Transform and DrawImage methods.publicclassStampImage {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();// Load an existing PDF to which we will add a stamp annotation // (see LoadPDF for details on loading documents):var jsFile = Path.Combine("Resources", "PDFs", "The-Rich-History-of-JavaScript.pdf");usingvar fs = File.OpenRead(jsFile); doc.Load(fs);var rect = newRectangleF(PointF.Empty, doc.Pages[0].Size);// Create a FormXObject to use as the stamp appearance:var fxo = newFormXObject(doc, rect);// Get an image from the resources, and draw it on the FormXObject's graphics// (see Transformations for details on using GcGraphics.Transform):usingvar image = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "draft-copy-450x72.png"));var center = newVector2(fxo.Bounds.Width / 2, fxo.Bounds.Height / 2); fxo.Graphics.Transform =Matrix3x2.CreateRotation((float)(-55 * Math.PI) / 180f, center) *Matrix3x2.CreateScale(6, center); fxo.Graphics.DrawImage(image, fxo.Bounds, null, ImageAlign.CenterImage);// Loop over pages, add a stamp to each page:foreach (var page in doc.Pages) {// Create a StampAnnotation over the whole page:var stamp = newStampAnnotation() {Icon = StampAnnotationIcon.Draft.ToString(),Name = "draft",Page = page,Rect = rect,UserName = "Jaime Smith" };// Re-use the same FormXObject on all pages: stamp.AppearanceStreams.Normal.Default = fxo; }// Done: doc.Save(stream);return doc.Pages.Count; } }}