public class

Stamper

extends Object
implements AutoCloseable
java.lang.Object
   ↳ com.pdftron.pdf.Stamper

Class Overview

Stamper is a utility class that can be used to PDF pages with text, images, or with other PDF content in only a few lines of code. Although Stamper is very simple to use compared to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you need full control over PDF creation use ElementBuilder/ElementWriter to add new content to existing PDF pages as shown in the ElementBuilder sample project.

Summary

Constants
int e_absolute_size The Constant e_absolute_size.
int e_align_center The Constant e_align_center.
int e_align_left The Constant e_align_left.
int e_align_right The Constant e_align_right.
int e_font_size The Constant e_font_size.
int e_horizontal_center The Constant e_horizontal_center.
int e_horizontal_left The Constant e_horizontal_left.
int e_horizontal_right The Constant e_horizontal_right.
int e_relative_scale The Constant e_relative_scale.
int e_vertical_bottom The Constant e_vertical_bottom.
int e_vertical_center The Constant e_vertical_center.
int e_vertical_top The Constant e_vertical_top.
Public Constructors
Stamper(int size_type, double a, double b)
Stamper constructor.
Public Methods
void close()
Frees the native memory of the object.
static void deleteStamps(PDFDoc doc, PageSet page_set)
Deletes PDFTron stamps from document at given page numbers.
void destroy()
Frees the native memory of the object.
static boolean hasStamps(PDFDoc doc, PageSet page_set)
Returns true if the given set of pages has at least one stamp.
void setAlignment(int horizontal_alignment, int vertical_alignment)
Set the alignment for the x and y variables.
void setAsAnnotation(boolean annotation)
Specifies if the stamp is to be stamped as an annotation.
void setAsBackground(boolean background)
Specifies if the stamp is to be stamped in the background or the foreground.
void setFont(Font font)
Defines the font of the stamp.
void setFontColor(ColorPt color)
Set the font color (This only effects text-based stamps).
void setOpacity(double opacity)
Set the opacity value for the stamp.
void setPosition(double horizontal_distance, double vertical_distance)
Set the horizontal and vertical position of the stamp.
void setPosition(double horizontal_distance, double vertical_distance, boolean percentage)
Set the horizontal and vertical position of the stamp.
void setRotation(double rotation)
Rotates the stamp by the given number of degrees.
void setSize(int size_type, double a, double b)
Set the size of the stamp.
void setTextAlignment(int text_alignment)
Set the text alignment (note: this only applies to text watermarks).
void showsOnPrint(boolean on_print)
Shows on print.
void showsOnScreen(boolean on_screen)
Shows on screen.
void stampImage(PDFDoc dest_doc, Image src_img, PageSet dest_pages)
Stamps an image to the given destination document at the set of page numbers.
void stampPage(PDFDoc dest_doc, Page src_page, PageSet dest_pages)
Stamps a PDF page to the given destination document at the set of page numbers.
void stampText(PDFDoc dest_doc, String src_txt, PageSet dest_pages)
Stamps text to the given destination document at the set of page numbers.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.AutoCloseable

Constants

public static final int e_absolute_size

The Constant e_absolute_size.

Constant Value: 2 (0x00000002)

public static final int e_align_center

The Constant e_align_center.

Constant Value: 0 (0x00000000)

public static final int e_align_left

The Constant e_align_left.

Constant Value: -1 (0xffffffff)

public static final int e_align_right

The Constant e_align_right.

Constant Value: 1 (0x00000001)

public static final int e_font_size

The Constant e_font_size.

Constant Value: 3 (0x00000003)

public static final int e_horizontal_center

The Constant e_horizontal_center.

Constant Value: 0 (0x00000000)

public static final int e_horizontal_left

The Constant e_horizontal_left.

Constant Value: -1 (0xffffffff)

public static final int e_horizontal_right

The Constant e_horizontal_right.

Constant Value: 1 (0x00000001)

public static final int e_relative_scale

The Constant e_relative_scale.

Constant Value: 1 (0x00000001)

public static final int e_vertical_bottom

The Constant e_vertical_bottom.

Constant Value: -1 (0xffffffff)

public static final int e_vertical_center

The Constant e_vertical_center.

Constant Value: 0 (0x00000000)

public static final int e_vertical_top

The Constant e_vertical_top.

Constant Value: 1 (0x00000001)

Public Constructors

public Stamper (int size_type, double a, double b)

Stamper constructor.

Parameters
size_type Specifies how the stamp will be sized -e_relative_scale: Stamp size is relative to the size of the crop box of the destination page. 'a' is a percentage of the width of the crop box (e.g.: 0.5 is 50% of the width of the crop box) 'b' is a percentage of the height of the crop box. If 'a' <= 0 then only b will be used. If 'b' <= 0 then only 'a' will be used. -e_absolute_scale: Stamp size is explicitly set. 'a' sets the width of of the stamp's bounding box. 'b' sets the height of the stamp's bounding box. The width and height are constant, regardless of the size of the destination page's bounding box. -e_font_size: This type only applies to text stamps. 'a' sets the font size. 'b' is ignored.
a width of the stamp bounding box
b height of the stamp bounding box

Public Methods

public void close ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public static void deleteStamps (PDFDoc doc, PageSet page_set)

Deletes PDFTron stamps from document at given page numbers.

Parameters
doc The document to delete stamps from
page_set The set of pages to delete stamps from

public void destroy ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public static boolean hasStamps (PDFDoc doc, PageSet page_set)

Returns true if the given set of pages has at least one stamp.

Parameters
doc The document that's being checked
page_set The set of page that's being checked
Returns
  • true, if successful

public void setAlignment (int horizontal_alignment, int vertical_alignment)

Set the alignment for the x and y variables.

Parameters
horizontal_alignment Can be set to e_left, e_center or e_right e_left: horizontal_distance measures the distance between the left edge of the stamp's bounding box and the left edge of the crop box e_center: horizontal_distance measures the distance between the horizontal bisector of the stamp's bounding box and the horizontal bisector of the crop box e_right: horizontal_distance measures the distance between the right edge of the stamp's bounding box and the right edge of the crop box
vertical_alignment the vertical_alignment

public void setAsAnnotation (boolean annotation)

Specifies if the stamp is to be stamped as an annotation.

Note: Stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.

Parameters
annotation A flag specifying if the stamp should be added as an annotation or not

public void setAsBackground (boolean background)

Specifies if the stamp is to be stamped in the background or the foreground.

Parameters
background A flag specifying if the stamp should be added as a background layer to the destination page

public void setFont (Font font)

Defines the font of the stamp. (This only applies to text-based stamps)

Parameters
font The font of the text stamp

public void setFontColor (ColorPt color)

Set the font color (This only effects text-based stamps).

Parameters
color the new font color

public void setOpacity (double opacity)

Set the opacity value for the stamp.

Parameters
opacity The opacity value of the stamp

public void setPosition (double horizontal_distance, double vertical_distance)

Set the horizontal and vertical position of the stamp.

Parameters
horizontal_distance Horizontal distance from left, right or center of crop box; in points
vertical_distance the vertical_distance

public void setPosition (double horizontal_distance, double vertical_distance, boolean percentage)

Set the horizontal and vertical position of the stamp.

Parameters
horizontal_distance Horizontal distance from left, right or center of crop box
vertical_distance the vertical_distance
percentage If true, horizontal_distance is a percentage of the crop box width (e.g.: 0.5 is 50% of the width of the crop box) and vertical_distance is a percentage of the crop box height. If false, horizontal_distance and vertical_distance is measured in points.

public void setRotation (double rotation)

Rotates the stamp by the given number of degrees.

Parameters
rotation Rotation in degrees

public void setSize (int size_type, double a, double b)

Set the size of the stamp.

Parameters
size_type Specifies how the stamp will be sized -e_relative_scale: Stamp size is relative to the size of the crop box of the destination page. 'a' is a percentage of the width of the crop box (e.g.: 0.5 is 50% of the width of the crop box) 'b' is a percentage of the height of the crop box. If 'a' <= 0 then only b will be used. If 'b' <= 0 then only 'a' will be used. -e_absolute_scale: Stamp size is explicitly set. 'a' sets the width of of the stamp's bounding box. 'b' sets the height of the stamp's bounding box. The width and height are constant, regardless of the size of the destination page's bounding box. -e_font_size: This type only applies to text stamps. 'a' sets the font size. 'b' is ignored.
a width of the bounding box
b height of the bounding box

public void setTextAlignment (int text_alignment)

Set the text alignment (note: this only applies to text watermarks).

Parameters
text_alignment Enumerator for text alignment (e_left, e_center, e_right)

public void showsOnPrint (boolean on_print)

Shows on print.

Parameters
on_print Specifies if the watermark will be displayed when printed

public void showsOnScreen (boolean on_screen)

Shows on screen.

Parameters
on_screen Specifies if the watermark will be displayed on screen

public void stampImage (PDFDoc dest_doc, Image src_img, PageSet dest_pages)

Stamps an image to the given destination document at the set of page numbers.

Parameters
dest_doc The document being stamped
src_img The image that is being stamped to the document
dest_pages The set of pages in the document being stamped

public void stampPage (PDFDoc dest_doc, Page src_page, PageSet dest_pages)

Stamps a PDF page to the given destination document at the set of page numbers.

Parameters
dest_doc The document being stamped
src_page The page that is being stamped to the document
dest_pages The set of pages in the document being stamped

public void stampText (PDFDoc dest_doc, String src_txt, PageSet dest_pages)

Stamps text to the given destination document at the set of page numbers.

Parameters
dest_doc The document being stamped
src_txt The image that is being stamped to the document
dest_pages The set of pages in the document being stamped