'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.NumericsImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.AnnotationsImportsGrapeCity.Documents.Pdf.GraphicsImportsGrapeCity.Documents.DrawingImports GCDRAW = GrapeCity.Documents.Drawing '' This sample demonstrates how to add a custom appearance stream'' to an annotation using a FormXObject.'' In the sample, an existing PDF is loaded, and then we loop over'' the document's pages. On each page, a StampAnnotation is created, and a FormXObject'' which is assigned to the annotation's normal default appearance stream.'' A semi-transparent PNG image is then drawn on the FormXObject's'' Graphics using regular GcGraphics features (Transform and DrawImage).PublicClassStampImageFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument() '' Load an existing PDF to which we will add a stamp annotation '' (see LoadPDF for details on loading documents):Dim jsFile = Path.Combine("Resources", "PDFs", "The-Rich-History-of-JavaScript.pdf")Using fs = NewFileStream(jsFile, FileMode.Open, FileAccess.Read) doc.Load(fs)Dim rect = NewRectangleF(PointF.Empty, doc.Pages(0).Size) '' Create a FormXObject to use as the stamp appearance:Dim 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):Dim img = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "draft-copy-450x72.png"))Dim center = NewVector2(fxo.Bounds.Width / 2, fxo.Bounds.Height / 2) fxo.Graphics.Transform =Matrix3x2.CreateRotation((-55 * Math.PI) / 180.0F, center) *Matrix3x2.CreateScale(6, center) fxo.Graphics.DrawImage(img, fxo.Bounds, Nothing, ImageAlign.CenterImage) '' Loop over pages, add a stamp to each page:ForEach page In doc.Pages'' Create a StampAnnotation over the whole page:Dim stamp = NewStampAnnotation() With { .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 = fxoNext'' doc.Save(stream)EndUsing'' Done:Return doc.Pages.CountEndFunctionEndClass