@Deprecated public abstract class DocumentPart extends Object
Represents any logical part of a document (page, frame, header or a whole document) where watermark can be placed.
Modifier and Type | Method and Description |
---|---|
void |
addWatermark(Watermark watermark)
Deprecated.
Adds a watermark to this
DocumentPart . |
WatermarkableImageCollection |
findImages()
Deprecated.
Finds all images in the document.
|
WatermarkableImageCollection |
findImages(ImageSearchCriteria searchCriteria)
Deprecated.
Finds images according to specified search criteria.
|
PossibleWatermarkCollection |
findWatermarks()
Deprecated.
Finds all possible watermarks in the document.
|
PossibleWatermarkCollection |
findWatermarks(SearchCriteria searchCriteria)
Deprecated.
Finds possible watermarks according to specified search criteria.
|
public final WatermarkableImageCollection findImages(ImageSearchCriteria searchCriteria)
Finds images according to specified search criteria.
The search is conducted in objects specified in Document.SearchableObjects
.
searchCriteria
- The search criteria to use.public final WatermarkableImageCollection findImages()
Finds all images in the document.
The search is conducted in objects specified in Document.SearchableObjects
.
This example demonstrates how to add watermark to all images in a document of any supported type.
Document document = Document.load("D:\\input.doc"); // Initialize text or image watermark. TextWatermark watermark = new TextWatermark("DRAFT", new Font("Arial", 19)); // Find all images in the document. WatermarkableImageCollection images = document.findImages(); // Add watermark. for (WatermarkableImage watermarkableImage : images) { watermarkableImage.addWatermark(watermark); } // Save changes. document.save("D:\\output.doc"); document.close();
public final PossibleWatermarkCollection findWatermarks(SearchCriteria searchCriteria)
Finds possible watermarks according to specified search criteria.
The search is conducted in objects specified in Document.SearchableObjects
.
searchCriteria
- The search criteria to use.
This example demonstrates how to find and remove all possible watermarks containing particular text or image from a document of any supported type.
Document document = Document.load("D:\\input.doc"); ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("D:\\logo.png"); Pattern regex = Pattern.compile("CompanyName", Pattern.CASE_INSENSITIVE); TextSearchCriteria textSearchCriteria = new TextSearchCriteria(regex); PossibleWatermarkCollection watermarks = document.findWatermarks(textSearchCriteria.or(imageSearchCriteria)); watermarks.clear(); document.save("D:\\output.doc"); document.close();
public final PossibleWatermarkCollection findWatermarks()
Finds all possible watermarks in the document.
The search is conducted in objects specified in Document.SearchableObjects
.
public void addWatermark(Watermark watermark)
Adds a watermark to this DocumentPart
.
watermark
- The watermark to add to the document.
This example demonstrates how to add image and text watermark to a document of any supported type.
Document document = Document.load("D:\\input.pdf"); TextWatermark textWatermark = new TextWatermark("DRAFT", new Font("Arial", 19)); textWatermark.setHorizontalAlignment(HorizontalAlignment.Center); textWatermark.setVerticalAlignment(VerticalAlignment.Top); textWatermark.setConsiderParentMargins(true); textWatermark.setForegroundColor(Color.getRed()); textWatermark.setBackground(true); textWatermark.setOpacity(0.5); document.addWatermark(textWatermark); ImageWatermark imageWatermark = new ImageWatermark("D:\\draft.png"); imageWatermark.setHorizontalAlignment(HorizontalAlignment.Center); imageWatermark.setVerticalAlignment(VerticalAlignment.Bottom); imageWatermark.setConsiderParentMargins(true); imageWatermark.setBackground(true); imageWatermark.setOpacity(0.5); document.addWatermark(imageWatermark); imageWatermark.close(); document.save("D:\\output.pdf"); document.close();