Class: Stamper

Core.PDFNet. Stamper


new Stamper()

Stamper is a utility class that can be used to stamp PDF pages with text, images, or vector art (including another PDF page) 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.

Extends

Members


<static> HorizontalAlignment

Type:
  • number
Properties:
Name Type Description
e_horizontal_left number
e_horizontal_center number
e_horizontal_right number

<static> SizeType

Type:
  • number
Properties:
Name Type Description
e_relative_scale number
e_absolute_size number
e_font_size number

<static> TextAlignment

Type:
  • number
Properties:
Name Type Description
e_align_left number
e_align_center number
e_align_right number

<static> VerticalAlignment

Type:
  • number
Properties:
Name Type Description
e_vertical_bottom number
e_vertical_center number
e_vertical_top number

Methods


<static> create(size_type, a, b)

Stamper constructor
Parameters:
Name Type Description
size_type number
PDFNet.Stamper.SizeType = {
	e_relative_scale : 1
	e_absolute_size : 2
	e_font_size : 3
}
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 number @see size_type
b number @see size_type
Returns:
A promise that resolves to an object of type: "PDFNet.Stamper"
Type
Promise.<Core.PDFNet.Stamper>

<static> deleteStamps(doc, page_set)

Deletes PDFTron stamps from document at given page numbers
Parameters:
Name Type Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc The document to delete stamps from
page_set Core.PDFNet.PageSet The set of pages to delete stamps from
Returns:
Type
Promise.<void>

<static> hasStamps(doc, page_set)

Returns true if the given set of pages has at least one stamp
Parameters:
Name Type Description
doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc The document that's being checked
page_set Core.PDFNet.PageSet The set of page that's being checked
Returns:
A promise that resolves to an object of type: "boolean"
Type
Promise.<boolean>

destroy()

Destructor
Inherited From:
Returns:
Type
Promise.<void>

setAlignment(horizontal_alignment, vertical_alignment)

Sets the alignment for the x and y variables.
Parameters:
Name Type Description
horizontal_alignment number
PDFNet.Stamper.HorizontalAlignment = {
	e_horizontal_left : -1
	e_horizontal_center : 0
	e_horizontal_right : 1
}
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 number
PDFNet.Stamper.VerticalAlignment = {
	e_vertical_bottom : -1
	e_vertical_center : 0
	e_vertical_top : 1
}
Can be set to e_top, e_center or e_bottom e_bottom: vertical_distance measures the distance between the bottom edge of the stamp's bounding box and the bottom edge of the crop box e_center: vertical_distance measures the distance between the vertical bisector of the stamp's bounding box and the vertical bisector of the crop box e_top: vertical_distance measures the distance between the top edge of the stamp's bounding box and the top edge of the crop box
See:
  • SetPosition
Returns:
Type
Promise.<void>

setAsAnnotation(annotation)

Specifies if the stamp is to be stamped as an annotation.
Parameters:
Name Type Description
annotation boolean A flag specifying if the stamp should be added as an annotation or not Note: Stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.
Returns:
Type
Promise.<void>

setAsBackground(background)

Specifies if the stamp is to be stamped in the background or the foreground.
Parameters:
Name Type Description
background boolean A flag specifying if the stamp should be added as a background layer to the destination page
Returns:
Type
Promise.<void>

setFont(font)

Defines the font of the stamp. (This only applies to text-based stamps)
Parameters:
Name Type Description
font Core.PDFNet.Font The font of the text stamp
Returns:
Type
Promise.<void>

setFontColor(font_color)

Sets the font color (This only effects text-based stamps)
Parameters:
Name Type Description
font_color Core.PDFNet.ColorPt The color of the font
Returns:
Type
Promise.<void>

setOpacity(opacity)

Sets the opacity value for the stamp
Parameters:
Name Type Description
opacity number The opacity value of the stamp
Returns:
Type
Promise.<void>

setPosition(horizontal_distance, vertical_distance [, use_percentage])

Sets the horizontal and vertical position of the stamp.
Parameters:
Name Type Argument Description
horizontal_distance number Horizontal distance from left, right or center of crop box
vertical_distance number Vertical distance from top, bottom or center of crop box
use_percentage boolean <optional>
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.
See:
  • SetAlignment
Returns:
Type
Promise.<void>

setRotation(rotation)

Rotates the stamp by the given number of degrees
Parameters:
Name Type Description
rotation number Rotation in degrees
Returns:
Type
Promise.<void>

setSize(size_type, a, b)

sets the size of the stamp
Parameters:
Name Type Description
size_type number
PDFNet.Stamper.SizeType = {
	e_relative_scale : 1
	e_absolute_size : 2
	e_font_size : 3
}
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 number Generally the horizontal component of the size. See size_type for more details.
b number Generally the vertical component of the size. See size_type for more details.
Returns:
Type
Promise.<void>

setTextAlignment(text_alignment)

Sets the text alignment (note: this only applies to text watermarks)
Parameters:
Name Type Description
text_alignment number
PDFNet.Stamper.TextAlignment = {
	e_align_left : -1
	e_align_center : 0
	e_align_right : 1
}
Enumerator for text alignment (e_left, e_center, e_right)
Returns:
Type
Promise.<void>

showsOnPrint(on_print)

Parameters:
Name Type Description
on_print boolean Specifies if the watermark will be displayed when printed
Returns:
Type
Promise.<void>

showsOnScreen(on_screen)

Parameters:
Name Type Description
on_screen boolean Specifies if the watermark will be displayed on screen
Returns:
Type
Promise.<void>

stampImage(dest_doc, img, dest_pages)

Stamps an image to the given destination document at the set of page numbers
Parameters:
Name Type Description
dest_doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc The document being stamped
img Core.PDFNet.Image The image that is being stamped to the document
dest_pages Core.PDFNet.PageSet The set of pages in the document being stamped
Returns:
Type
Promise.<void>

stampPage(dest_doc, page, dest_pages)

Stamps a PDF page to the given destination document at the set of page numbers
Parameters:
Name Type Description
dest_doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc The document being stamped
page Core.PDFNet.Page The page that is being stamped to the document
dest_pages Core.PDFNet.PageSet The set of pages in the document being stamped
Returns:
Type
Promise.<void>

stampText(dest_doc, txt, dest_pages)

Stamps text to the given destination document at the set of page numbers
Parameters:
Name Type Description
dest_doc Core.PDFNet.PDFDoc | Core.PDFNet.SDFDoc | Core.PDFNet.FDFDoc The document being stamped
txt string The image that is being stamped to the document
dest_pages Core.PDFNet.PageSet The set of pages in the document being stamped
Returns:
Type
Promise.<void>

takeOwnership()

Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
Inherited From:
Returns:
Type
void