Back to Devexpress

PdfRubberStampAnnotationFacade Class

officefileapi-devexpress-dot-pdf-60a9e53d.md

latest13.7 KB
Original Source

PdfRubberStampAnnotationFacade Class

Contains members used to manage rubber stamp annotations without access to their inner structure.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfRubberStampAnnotationFacade :
    PdfMarkupAnnotationFacade
vb
Public Class PdfRubberStampAnnotationFacade
    Inherits PdfMarkupAnnotationFacade

The following members return PdfRubberStampAnnotationFacade objects:

Remarks

Create Rubber Stamp Annotations

The following code snippet creates a Top Secret rubber stamp:

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade page = processor.DocumentFacade.Pages[0];

    // Define a rubber stamp rectangle
    PdfRectangle rubberStampRectangle = new PdfRectangle(663, 526, 763, 576);

    // Create a rubber stamp in this rectangle
    PdfRubberStampAnnotationFacade rubberStamp =
       page.AddRubberStampAnnotation(rubberStampRectangle, PdfRubberStampAnnotationIconName.TopSecret);
    rubberStamp.Author = "Jesse Faden";
    rubberStamp.Contents = "Made in PDF Document API";
}
vb
Using processor As New PdfDocumentProcessor()
  'Load a document.
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties.
  Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Define a rubber stamp rectangle
  Dim rubberStampRectangle As New PdfRectangle(663, 526, 763, 576)

  ' Create a rubber stamp in this rectangle
  Dim rubberStamp As PdfRubberStampAnnotationFacade =
     page.AddRubberStampAnnotation(rubberStampRectangle, PdfRubberStampAnnotationIconName.TopSecret)
  rubberStamp.Author = "Jesse Faden"
  rubberStamp.Contents = "Made in PDF Document API"

End Using

Create a Dynamic Rubber Stamp

Specify one of the following icon names as the PdfPageFacade.AddRubberStampAnnotation method parameter to create a dynamic rubber stamp:

Icon NameRubber Stamp
DReviewed
DRevised
DApproved
DConfidential
DReceived

Use the Author and ModificationDate properties to specify the author and the date displayed in the rubber stamp.

The following code snippet creates a Reviewed dynamic stamp:

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page's properties
    PdfPageFacade page = processor.DocumentFacade.Pages[0];

    // Define a rubber stamp rectangle
    PdfRectangle rubberStampRectangle = new PdfRectangle(663, 526, 763, 576);

    // Create a "Top Secret" rubber stamp annotation
    PdfRubberStampAnnotationFacade rubberStamp =
       page.AddRubberStampAnnotation(rubberStampRectangle, PdfRubberStampAnnotationIconName.DReviewed);
    rubberStamp.Author = "Jesse Faden";
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page's properties
  Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Define a rubber stamp rectangle
  Dim rubberStampRectangle As New PdfRectangle(663, 526, 763, 576)

  ' Create a "Top Secret" rubber stamp
  Dim rubberStamp As PdfRubberStampAnnotationFacade =
     page.AddRubberStampAnnotation(rubberStampRectangle, PdfRubberStampAnnotationIconName.DReviewed)
  rubberStamp.Author = "Jesse Faden"
End Using

Create an Annotation with a Custom Stamp

You can generate a stamp from another document’s page. Pass the path to a file and a page number as the PdfPageFacade.AddRubberStampAnnotation method parameters to create a custom stamp.

The following code snippet generates a custom stamp from another document:

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page's properties
    PdfPageFacade page = processor.DocumentFacade.Pages[0];

    // Define a a rubber stamp rectangle
    PdfRectangle rubberStampRectangle = new PdfRectangle(663, 526, 763, 576);

    // Specify a document to use as a custom stamp
    string customStampFile = "..\\..\\Demo.pdf";

    // Create a rubber stamp annotation
    PdfRubberStampAnnotationFacade rubberStamp =
       page.AddRubberStampAnnotation(rubberStampRectangle, customStampFile, 2);
    rubberStamp.Author = "Jesse Faden";

    // Save the result
    processor.SaveDocument("..\..\Result.pdf")

}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page's properties
  Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Define a rubber stamp rectangle
  Dim rubberStampRectangle As New PdfRectangle(663, 526, 763, 576)

  ' Specify a document to use as a custom stamp
  Dim customStampFile As String = "..\..\Demo.pdf"

  ' Create a rubber stamp annotation
  Dim rubberStamp As PdfRubberStampAnnotationFacade =
     page.AddRubberStampAnnotation(rubberStampRectangle, customStampFile, 2)
  rubberStamp.Author = "Jesse Faden"

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Edit Rubber Stamp Annotations

The PdfPageFacade.Annotations property returns all page annotation properties. You can filter rubber stamp annotation properties, cast them to the PdfRubberStampAnnotationFacade class, and use class properties to modify annotation parameters.

The following code snippet retrieves all rubber stamps, and changes their icon and author:

csharp
using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page's properties
    PdfPageFacade page = processor.DocumentFacade.Pages[0];

    // Retrieve all rubber stamp annotations
    var rubberStamps = page.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.RubberStamp);

    // Change rubber stamp parameters
    foreach (PdfRubberStampAnnotationFacade rubberStamp in rubberStamps) 
    {
        rubberStamp.Author = "Brian Zetc";
        rubberStamp.IconName = PdfRubberStampAnnotationIconName.Confidential;
        rubberStamp.Opacity = 0.5;
    }

}
vb
Imports DevExpress.Pdf
Imports System.Linq

Using processor As New PdfDocumentProcessor()

  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page's properties
  Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all rubber stamp annotations
  Dim rubberStamps = page.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.RubberStamp)

  ' Change rubber stamp parameters
  For Each rubberStamp As PdfRubberStampAnnotationFacade In rubberStamps
    rubberStamp.Author = "Brian Zetc"
    rubberStamp.IconName = PdfRubberStampAnnotationIconName.Confidential
    rubberStamp.Opacity = 0.5
  Next rubberStamp
End Using

Flatten Rubber Stamp Annotations

Call one of the following methods to flatten an annotation:

MethodDescription
PdfDocumentFacade.FlattenAnnotationsFlattens document annotations.
PdfPageFacade.FlattenAnnotationsFlattens annotations of a specific page.
PdfAnnotationFacade.Flatten()Flattens a specific annotation.

The following code snippet flattens all rubber stamp annotations on the first page.

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page's properties
    PdfPageFacade page = processor.DocumentFacade.Pages[0];

    // Flatten all rubber stamps
    page.FlattenAnnotations(PdfAnnotationType.RubberStamp);
}
vb
Using processor As New PdfDocumentProcessor()

  'Load a document:
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page's properties
  Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Flatten all rubber stamp annotations
  page.FlattenAnnotations(PdfAnnotationType.RubberStamp)
End Using

Remove Rubber Stamp Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The following code snippet removes all rubber stamps on the first page.

csharp
using DevExpress.Pdf;
using System.Linq;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{

  // Load a document
  processor.LoadDocument("..\\..\\Document.pdf");

  // Access the first page's properties 
  PdfPageFacade page = processor.DocumentFacade.Pages[0];

  // Retrieve all rubber stamps
  var rubberStamps = page.Annotations.Where
    (annotation => annotation.Type == PdfAnnotationType.RubberStamp).ToList();

  // Remove all rubber stamps
  foreach (PdfRubberStampAnnotationFacade rubberStamp in rubberStamps)
  {
      rubberStamp.Remove();
  }
}
vb
Imports DevExpress.Pdf
Imports System.Linq

Using processor As New PdfDocumentProcessor()
processor

  'Load a document:
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page's properties
  Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all rubber stamps
  Dim rubberStamps = page.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.RubberStamp).ToList()

  ' Remove all rubber stamps
  For Each rubberStamp As PdfRubberStampAnnotationFacade In rubberStamps
    rubberStamp.Remove()
  Next rubberStamp
End Using

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfRubberStampAnnotationFacade

See Also

PdfRubberStampAnnotationFacade Members

DevExpress.Pdf Namespace