Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GroupDocs.Watermark-for-Java 18.1
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
String inputFolder = "D:\\docs\\input\\";
String outputFolder = "D:\\docs\\output\\";
// Get files
File[] files = new File(inputFolder).listFiles();
// Create text watermark
Font font = new Font("Arial", 8, FontStyle.Bold);
TextWatermark watermark = new TextWatermark("CONFIDENTIAL", font);
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(-45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(0.8);
watermark.setOpacity(0.5);
watermark.setForegroundColor(Color.getRed());
// Add watermark to all files
for (File file : files)
{
if (file.isFile())
{
Document doc = null;
try
{
doc = Document.load(file.getAbsolutePath());
doc.addWatermark(watermark);
doc.save(outputFolder + file.getName());
}
catch (UnsupportedFileTypeException exception)
{
System.out.println("File format is not supported. File = " + file.getName());
}
finally
{
if (doc != null)
{
doc.close();
}
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Setup license
License lic = new License();
lic.setLicense(LICENSE_PATH);
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Setup license
License lic = new License();
lic.setLicense(new java.io.FileInputStream(LICENSE_PATH));
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// initialize Metered API
Metered metered = new Metered();
// set-up credentials
metered.setMeteredKey(publicKey, privateKey);
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Get document info
DocumentInfo documentInfo = Document.getInfo(Common.mapSourceFilePath(fileName));
// Display document info
System.out.println(documentInfo.getFileFormat());
System.out.println(documentInfo.isEncrypted());
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
public static Path getProjectBaseDir() {
Properties props = new Properties();
try {
InputStream i = Common.class.getResourceAsStream("/project.properties");
props.load(i);
} catch (IOException x) {
throw new RuntimeException(x);
}
return FileSystems.getDefault().getPath(props.getProperty("project.basedir"));
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
Document doc = Document.load(Common.mapSourceFilePath(fileName));
// Here we can use document instance to add or remove watermarks
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
InputStream inputStream = new FileInputStream(Common.mapSourceFilePath(fileName));
Document doc = Document.load(inputStream);
// Here we can use document instance to add or remove watermarks
doc.close();
inputStream.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Use LoadOptions instance to pass the password
LoadOptions loadOptions = new LoadOptions();
loadOptions.setPassword("123");
Document doc = Document.load(Common.mapSourceFilePath(fileName), loadOptions);
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
public static String mapSourceFilePath(String inputFileName) {
try {
return STORAGE_PATH + "/" + inputFileName;
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
String inputFolder = "D:\\docs\\input\\";
String outputFolder = "D:\\docs\\output\\";
String logo = "D:\\docs\\logo.png";
// Get file listing
File[] files = new File(inputFolder).listFiles();
// Create image search criteria
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(logo);
Pattern pattern = Pattern.compile("^Company\\s+Name$", Pattern.CASE_INSENSITIVE);
TextSearchCriteria textSearchCriteria = new TextSearchCriteria(pattern);
for (File file : files)
{
if (file.isFile())
{
Document doc = null;
try
{
doc = Document.load(file.getAbsolutePath());
PossibleWatermarkCollection watermarks = doc.findWatermarks(textSearchCriteria.or(imageSearchCriteria));
watermarks.clear();
doc.save(outputFolder + file.getName());
}
catch (UnsupportedFileTypeException exception)
{
System.out.println("File format is not supported. File = " + file.getName());
}
finally
{
if (doc != null)
{
doc.close();
}
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Document doc = Document.load(Common.mapSourceFilePath(fileName));
// Watermarking goes here
// ...
// Save the document to the specified location
doc.save("D:\\result.doc");
// Save the document to the specified stream
doc.save(outputStream);
doc.close();
// Use the stream containing the document
//..
outputStream.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
doc.addAnnotationWatermark(imageWatermark);
imageWatermark.close();
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
doc.addAnnotationWatermark(textWatermark);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
doc.addArtifactWatermark(imageWatermark);
imageWatermark.close();
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
doc.addArtifactWatermark(textWatermark);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Set attachment file path
String attachmentPath = Common.mapSourceFilePath("sample.docx");
File attachmentFile = new File(attachmentPath);
byte[] attachmentBytes = new byte[(int) attachmentFile.length()];
InputStream attachmentInputStream = new FileInputStream(attachmentFile);
attachmentInputStream.read(attachmentBytes);
attachmentInputStream.close();
// Add attachment
doc.getAttachments().add(attachmentBytes, "sample.docx");
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Set attachment file path
String attachmentPath = Common.mapSourceFilePath("sample.docx");
File file = new File(attachmentPath);
byte[] attachmentBytes = new byte[(int) file.length()];
InputStream inputStream = new FileInputStream(file);
inputStream.read(attachmentBytes);
inputStream.close();
// Set attachment preview image path
String previewImagePath = Common.mapSourceFilePath("sample.png");
file = new File(previewImagePath);
byte[] previewImageBytes = new byte[(int) file.length()];
inputStream = new FileInputStream(file);
inputStream.read(previewImageBytes);
inputStream.close();
// Get worksheet
CellsWorksheet worksheet = doc.getWorksheets().get_Item(0);
// Add the attachment
worksheet.getAttachments().addAttachment(attachmentBytes, // File content
attachmentPath, // Source file full name (the extension is used to determine appropriate application to open the file)
previewImageBytes, // Preview image content
50, // X-coordinate of the attachment frame
100, // Y-coordinate of the attachment frame
200, // Attachment frame width
400); // Attachment frame height
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Set attachment file path
String attachmentPath = Common.mapSourceFilePath("sample.docx");
File attachmentFile = new File(attachmentPath);
byte[] attachmentBytes = new byte[(int) attachmentFile.length()];
InputStream attachmentInputStream = new FileInputStream(attachmentFile);
attachmentInputStream.read(attachmentBytes);
attachmentInputStream.close();
// Load document
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add the attachment
doc.getAttachments().add(attachmentBytes, "License Agreement.doc", "end-user license agreement");
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load email document
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// initialize image's path
String imagePath = Common.WATERMARK_IMAGE_PATH;
File imageFile = new File(imagePath);
byte[] imageBytes = new byte[(int) imageFile.length()];
InputStream imageInputStream = new FileInputStream(imageFile);
imageInputStream.read(imageBytes);
imageInputStream.close();
// Add image to document
doc.getEmbeddedObjects().add(imageBytes, imagePath);
EmailEmbeddedObject embeddedObject = doc.getEmbeddedObjects()
.get_Item(doc.getEmbeddedObjects().getCount() - 1);
doc.setHtmlBody("<html><body>This is an embedded image: <img src=\"cid:" + embeddedObject.getContentId()
+ "\"></body></html>");
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Set properties
watermark.setVerticalAlignment(VerticalAlignment.Top);
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Add watermark
doc.getWorksheets().get_Item(0).addWatermarkIntoHeaderFooter(watermark);
watermark.close();
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Add watermark to all visible headers of the first section
doc.getSections().get_Item(0).addWatermark(watermark);
watermark.close();
// Link all other headers&footers to corresponding
// headers&footers of the first section
for (int i = 1; i < doc.getSections().getCount(); i++) {
doc.getSections().get_Item(i).getHeadersFooters().linkToPrevious(true);
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize attachment path and preview image path
String attachmentPath = Common.mapSourceFilePath("sample.docx");
String previewImagePath = Common.mapSourceFilePath("sample.png");
File file = new File(previewImagePath);
byte[] previewImageBytes = new byte[(int) file.length()];
FileInputStream inputStream = new FileInputStream(file);
inputStream.read(previewImageBytes);
inputStream.close();
// Get worksheet from document
CellsWorksheet worksheet = doc.getWorksheets().get_Item(0);
// Add the attachment
worksheet.getAttachments().addLink(attachmentPath, // Source
// file path
previewImageBytes, // Preview image content
50, // X-coordinate of the attachment frame
100, // Y-coordinate of the attachment frame
200, // Attachment frame width
400); // Attachment frame height
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
// Settings to lock watermark
CellsShapeSettings settings = new CellsShapeSettings();
settings.setLocked(true);
// Add watermark
doc.getWorksheets().get_Item(0).addWatermark(textWatermark, settings);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
// Settings to lock watermark
SlidesShapeSettings settings = new SlidesShapeSettings();
settings.setLocked(true);
// Add watermark
doc.getSlides().get_Item(0).addWatermark(textWatermark, settings);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Calibri", 19));
// Setting to lock watermark
DiagramShapeSettings settings = new DiagramShapeSettings();
settings.setLocked(true);
// Add watermark
doc.getPages().get_Item(0).addWatermark(textWatermark, settings);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 36));
doc.getWorksheets().get_Item(0).addModernWordArtWatermark(textWatermark);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark textWatermark = new TextWatermark("This is a test watermark", new Font("Arial", 8));
boolean isPrintOnly = true;
// Annotation will be printed, but not displayed in pdf viewing
// application
doc.getPages().get_Item(0).addAnnotationWatermark(textWatermark, isPrintOnly);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Segoe UI", 19, FontStyle.Bold));
watermark.setForegroundColor(Color.getRed());
watermark.setVerticalAlignment(VerticalAlignment.Top);
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
// Add watermark
doc.getWorksheets().get_Item(0).addWatermarkIntoHeaderFooter(watermark);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Add watermark as background
doc.addWatermarkAsBackground(watermark);
watermark.close();
// Save Document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(90);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(0.5);
// Add watermark
doc.getWorksheets().get_Item(0).addWatermarkAsBackground(watermark, doc.getWorksheets().get_Item(0)
.getContentAreaWidthPx() /* set background width */,
doc.getWorksheets().get_Item(0)
.getContentAreaHeightPx() /*
* set background
* height
*/);
watermark.close();
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(0.5);
watermark.setOpacity(0.5);
// Add watermark
doc.getWorksheets().get_Item(0).addWatermarkAsBackground(watermark, doc.getWorksheets().get_Item(0)
.getContentAreaWidthPx() /* set background width */,
doc.getWorksheets().get_Item(0)
.getContentAreaHeightPx() /*
* set background
* height
*/);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
// Loop through attachments
for (EmailAttachment attachment : doc.getAttachments()) {
// Check if the attached file is supported by
// GroupDocs.Watermark
if (attachment.getDocumentInfo().getFileFormat() != FileFormat.Undefined
&& !attachment.getDocumentInfo().isEncrypted()) {
// Load the attached document
Document attachedDocument = attachment.loadDocument();
// Add watermark
attachedDocument.addWatermark(watermark);
// Save changes in the attached file
attachment.updateDocument(attachedDocument);
attachedDocument.close();
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop thourgh slides
for (SlidesSlide slide : doc.getSlides()) {
if (slide.getImageFillFormat().getBackgroundImage() != null) {
// Add watermark to the image
slide.getImageFillFormat().getBackgroundImage().addWatermark(watermark);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark 1", new Font("Calibri", 19));
// Add text watermark to all background pages
doc.addWatermark(textWatermark, DiagramWatermarkPlacementType.BackgroundPages);
// Initialize image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Add image watermark to all background pages
doc.addWatermark(imageWatermark, DiagramWatermarkPlacementType.ForegroundPages);
imageWatermark.close();
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 8));
// Add watermark to all master slides
for (SlidesMasterSlide slide : doc.getMasterSlides()) {
slide.addWatermark(watermark);
}
// Add watermark to all layout slides
if (doc.getLayoutSlides() != null) {
for (SlidesLayoutSlide slide : doc.getLayoutSlides()) {
slide.addWatermark(watermark);
}
}
// Add watermark to all notes slides
for (SlidesSlide slide : doc.getSlides()) {
if (slide.getNotesSlide() != null) {
slide.getNotesSlide().addWatermark(watermark);
}
}
// Add watermark to handout master
if (doc.getMasterHandoutSlide() != null) {
doc.getMasterHandoutSlide().addWatermark(watermark);
}
// Add watermark to notes master
if (doc.getMasterNotesSlide() != null) {
doc.getMasterNotesSlide().addWatermark(watermark);
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
for (PdfPage page : doc.getPages()) {
for (PdfAnnotation annotation : page.getAnnotations()) {
if (annotation.getImage() != null) {
// Add watermark to the image
annotation.getImage().addWatermark(watermark);
}
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through pages and add watermark
for (PdfPage page : doc.getPages()) {
for (PdfArtifact artifact : page.getArtifacts()) {
if (artifact.getImage() != null) {
// Add watermark to the image
artifact.getImage().addWatermark(watermark);
}
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
// Loop through worksheets
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (CellsAttachment attachment : worksheet.getAttachments()) {
// Check if the attached file is supported by
// GroupDocs.Watermark
if (attachment.getDocumentInfo().getFileFormat() != FileFormat.Undefined
&& !attachment.getDocumentInfo().isEncrypted()) {
// Load the attached document
Document attachedDocument = attachment.loadDocument();
// Add wateramrk
attachedDocument.addWatermark(watermark);
// Save changes in the attached file
attachment.updateDocument(attachedDocument);
attachedDocument.close();
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (PdfAttachment attachment : doc.getAttachments()) {
// Check if the attached file is supported by
// GroupDocs.Watermark
if (attachment.getDocumentInfo().getFileFormat() != FileFormat.Undefined
&& !attachment.getDocumentInfo().isEncrypted()) {
// Load the attached document
Document attachedDocument = attachment.loadDocument();
// Add wateramrk
attachedDocument.addWatermark(watermark);
// Save changes in the attached file
attachment.updateDocument(attachedDocument);
// Close the attached document
attachedDocument.close();
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through worksheets
for (CellsWorksheet worksheet : doc.getWorksheets()) {
if (worksheet.getBackgroundImage() != null) {
// Add watermark to the image
worksheet.getBackgroundImage().addWatermark(watermark);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
doc.getWorksheets().get_Item(0).addWatermark(textWatermark);
// Add image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
doc.getWorksheets().get_Item(0).addWatermark(imageWatermark);
imageWatermark.close();
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Get all images from the first worksheet
WatermarkableImageCollection images = doc.getWorksheets().get_Item(0).findImages();
// Add watermark to all found images
for (WatermarkableImage image : images) {
image.addWatermark(watermark);
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through worksheets
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (CellsShape shape : worksheet.getShapes()) {
if (shape.getImage() != null) {
// Add watermark to the image
shape.getImage().addWatermark(watermark);
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through slides
for (SlidesSlide slide : doc.getSlides()) {
for (SlidesShape shape : slide.getShapes()) {
if (shape.getImage() != null) {
// Add watermark to the image
shape.getImage().addWatermark(watermark);
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through sections
for (WordsSection section : doc.getSections()) {
for (WordsShape shape : section.getShapes()) {
// Headers&Footers usually contains only service
// information.
// So, we skip images in headers/footers, expecting that
// they are probably watermarks or backgrounds
if (shape.getHeaderFooter() == null && shape.getImage() != null) {
shape.getImage().addWatermark(watermark);
}
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through worksheets
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (CellsHeaderFooter headerFooter : worksheet.getHeadersFooters()) {
for (CellsHeaderFooterSection section : headerFooter.getSections()) {
if (section.getImage() != null) {
// Add watermark to the image
section.getImage().addWatermark(watermark);
}
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Get all images from the first page
WatermarkableImageCollection images = doc.getPages().get_Item(0).findImages();
// Add watermark to all found images
for (WatermarkableImage image : images) {
image.addWatermark(watermark);
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Get all images from the first slide
WatermarkableImageCollection images = doc.getSlides().get_Item(0).findImages();
// Add watermark to all found images
for (WatermarkableImage image : images) {
image.addWatermark(watermark);
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Get all images from the first slide
WatermarkableImageCollection images = doc.getPages().get_Item(0).findImages();
// Add watermark to all found images
for (WatermarkableImage image : images) {
image.addWatermark(watermark);
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Get all images belonging to the first section
WatermarkableImageCollection images = doc.getSections().get_Item(0).findImages();
// Add watermark to all found images
for (WatermarkableImage image : images) {
image.addWatermark(watermark);
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
TextWatermark textWatermark = new TextWatermark("DRAFT", new Font("Arial", 42));
// Add watermark to the last page
doc.addWatermark(textWatermark, doc.getPageCount());
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Calibri", 19));
doc.getPages().get_Item(0).addWatermark(textWatermark);
// Add image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
doc.getPages().get_Item(0).addWatermark(imageWatermark);
imageWatermark.close();
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
doc.getPages().get_Item(0).addWatermark(textWatermark);
// Add image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
doc.getPages().get_Item(1).addWatermark(imageWatermark);
imageWatermark.close();
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Add text watermark
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
doc.getSlides().get_Item(0).addWatermark(textWatermark);
// Add image watermark
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
doc.getSlides().get_Item(1).addWatermark(imageWatermark);
imageWatermark.close();
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
// Add watermark to all visible headers of the first section
doc.getSections().get_Item(0).addWatermark(watermark);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize watermark of any supported type
TextWatermark textWatermark = new TextWatermark("Test watermark 1", new Font("Calibri", 19));
// Create separate background for each page where it is not set.
// Add watermark to it.
doc.addWatermark(textWatermark, DiagramWatermarkPlacementType.SeparateBackgrounds);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Protected image", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Loop through pages
for (PdfPage page : doc.getPages()) {
for (PdfXObject xObject : page.getXObjects()) {
if (xObject.getImage() != null) {
// Add watermark to the image
xObject.getImage().addWatermark(watermark);
}
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 36));
CellsShapeSettings shapeSettings = new CellsShapeSettings();
// Set the shape name
shapeSettings.setName("Shape 1");
// Set the descriptive (alternative) text that will be associated with the shape
shapeSettings.setAlternativeText("Test watermark");
// Editing of the shape in Excel is forbidden
shapeSettings.setLocked(true);
doc.addModernWordArtWatermark(textWatermark, shapeSettings);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Create image effects
SlidesImageEffects effects = new SlidesImageEffects();
effects.setBrightness(0.7);
effects.setContrast(0.6);
effects.setChromaKey(Color.getWhite()); // setChromaKey method doesn't work for ppt files at this moment.
effects.getBorderLineFormat().setEnabled(true);
effects.getBorderLineFormat().setWeight(1);
// Add watermark
doc.addImageWatermark(watermark, effects);
watermark.close();
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Create cells image effects
CellsImageEffects effects = new CellsImageEffects();
effects.setBrightness(0.7);
effects.setContrast(0.6);
effects.setChromaKey(Color.getWhite());
effects.getBorderLineFormat().setEnabled(true);
effects.getBorderLineFormat().setWeight(1);
// Add watermark
doc.addImageWatermark(watermark, effects);
watermark.close();
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Create Word image effects
WordsImageEffects effects = new WordsImageEffects();
effects.setBrightness(0.7);
effects.setContrast(0.6);
effects.setChromaKey(Color.getWhite());
effects.getBorderLineFormat().setEnabled(true);
effects.getBorderLineFormat().setWeight(1);
// Add watermark
doc.addImageWatermark(watermark, effects);
watermark.close();
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 42));
watermark.setHorizontalAlignment(HorizontalAlignment.Right);
watermark.setVerticalAlignment(VerticalAlignment.Top);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
doc.setPageMarginType(PdfPageMarginType.BleedBox);
watermark.setConsiderParentMargins(true);
// Add watermark
doc.addWatermark(watermark);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
watermark.setBackground(true);
SlidesShapeSettings shapeSettings = new SlidesShapeSettings();
// Set the shape name
shapeSettings.setName("Shape 1");
// Set the descriptive (alternative) text that will be
// associated with the shape
shapeSettings.setAlternativeText("Test watermark");
// Editing of the shape in PowerPoint is forbidden
shapeSettings.setLocked(true);
// Add watermark
doc.addWatermark(watermark, shapeSettings);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Segoe UI", 19));
// Create slides text effects
SlidesTextEffects effects = new SlidesTextEffects();
effects.getLineFormat().setEnabled(true);
effects.getLineFormat().setColor(Color.getRed());
effects.getLineFormat().setDashStyle(OfficeDashStyle.DashDotDot);
effects.getLineFormat().setLineStyle(OfficeLineStyle.Triple);
effects.getLineFormat().setWeight(1);
// Add watermark
doc.addTextWatermark(watermark, effects);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Segoe UI", 19));
// Create cells text effects
CellsTextEffects effects = new CellsTextEffects();
effects.getLineFormat().setEnabled(true);
effects.getLineFormat().setColor(Color.getRed());
effects.getLineFormat().setDashStyle(OfficeDashStyle.DashDotDot);
effects.getLineFormat().setLineStyle(OfficeLineStyle.Triple);
effects.getLineFormat().setWeight(1);
// Add watermark
doc.addTextWatermark(watermark, effects);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
// Create Word text effects
WordsTextEffects effects = new WordsTextEffects();
effects.getLineFormat().setEnabled(true);
effects.getLineFormat().setColor(Color.getRed());
effects.getLineFormat().setDashStyle(OfficeDashStyle.DashDotDot);
effects.getLineFormat().setLineStyle(OfficeLineStyle.Triple);
effects.getLineFormat().setWeight(1);
// Add watermark
doc.addTextWatermark(watermark, effects);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create text watermark
TextWatermark watermark = new TextWatermark("This is test watermark", new Font("Arial", 19));
WordsShapeSettings shapeSettings = new WordsShapeSettings();
//Some settings for watermark
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setRotateAngle(25.0);
watermark.setForegroundColor(Color.getRed());
watermark.setOpacity(1.0);
// Set the shape name
shapeSettings.setName("Shape 1");
// Set the descriptive (alternative) text that will be
// associated with the shape
shapeSettings.setAlternativeText("Test watermark");
// Add watermark
doc.addWatermark(watermark, shapeSettings);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get headers and footers and clear sections
CellsHeaderFooterSectionCollection sections = doc.getWorksheets().get_Item(0).getHeadersFooters()
.getByOfficeHeaderFooterType(OfficeHeaderFooterType.HeaderPrimary).getSections();
for (CellsHeaderFooterSection section : sections) {
section.setScript(null);
section.setImage(null);
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get headers and footers
CellsHeaderFooterSection section = doc.getWorksheets().get_Item(0).getHeadersFooters()
.getByOfficeHeaderFooterType(OfficeHeaderFooterType.HeaderPrimary).getSections()
.getByCellsHeaderFooterSectionType(CellsHeaderFooterSectionType.Left);
section.setScript(null);
section.setImage(null);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Set folder to save attachments
String targetFolder = Common.ATTACHMENTS_PATH;
// Get attachments
for (EmailAttachment attachment : doc.getAttachments()) {
System.out.println("Name: " + attachment.getName());
System.out.println("File format: " + attachment.getDocumentInfo().getFileFormat());
// Save attacment
FileOutputStream outputStream = new FileOutputStream(targetFolder + "\\" + attachment.getName());
outputStream.write(attachment.getContent());
outputStream.close();
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get pages and their info
for (PdfPage page : doc.getPages()) {
for (PdfAnnotation annotation : page.getAnnotations()) {
System.out.println(annotation.getAnnotationType());
if (annotation.getImage() != null) {
System.out.println(annotation.getImage().getWidth());
System.out.println(annotation.getImage().getHeight());
System.out.println(annotation.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : annotation.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(annotation.getText());
System.out.println(annotation.getX());
System.out.println(annotation.getY());
System.out.println(annotation.getWidth());
System.out.println(annotation.getHeight());
System.out.println(annotation.getRotateAngle());
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (PdfPage page : doc.getPages()) {
for (PdfArtifact artifact : page.getArtifacts()) {
System.out.println(artifact.getArtifactType());
System.out.println(artifact.getArtifactSubtype());
if (artifact.getImage() != null) {
System.out.println(artifact.getImage().getWidth());
System.out.println(artifact.getImage().getHeight());
System.out.println(artifact.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : artifact.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(artifact.getText());
System.out.println(artifact.getOpacity());
System.out.println(artifact.getX());
System.out.println(artifact.getY());
System.out.println(artifact.getWidth());
System.out.println(artifact.getHeight());
System.out.println(artifact.getRotateAngle());
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (CellsAttachment attachment : worksheet.getAttachments()) {
System.out.println("Alternative text: " + attachment.getAlternativeText());
System.out.println("Attachment frame x-coordinate: " + attachment.getX());
System.out.println("Attachment frame y-coordinate: " + attachment.getY());
System.out.println("Attachment frame width: " + attachment.getWidth());
System.out.println("Attachment frame height: " + attachment.getHeight());
System.out.println("Preview image size: " + attachment.getPreviewImageContent() != null
? attachment.getPreviewImageContent().length : 0);
if (attachment.isLink()) {
// The document contains only a link to the attached
// file
System.out.println("Full path to the attached file: " + attachment.getSourceFullName());
} else {
// The attached file is stored in the document
System.out.println("File format: " + attachment.getDocumentInfo().getFileFormat());
System.out.println("Name of the source file: " + attachment.getSourceFullName());
System.out.println("File size: " + attachment.getContent().length);
}
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
String targetFolder = Common.ATTACHMENTS_PATH;
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get attachments
for (PdfAttachment attachment : doc.getAttachments()) {
System.out.println("Name: " + attachment.getName());
System.out.println("Description: " + attachment.getDescription());
System.out.println("File format: " + attachment.getDocumentInfo().getFileFormat());
// Save the attached file on disk
FileOutputStream fileStream = new FileOutputStream(targetFolder + "\\" + attachment.getName());
fileStream.write(attachment.getContent());
fileStream.close();
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (PdfPage page : doc.getPages()) {
for (PdfXObject xObject : page.getXObjects()) {
if (xObject.getImage() != null) {
System.out.println(xObject.getImage().getWidth());
System.out.println(xObject.getImage().getHeight());
System.out.println(xObject.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : xObject.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(xObject.getText());
System.out.println(xObject.getX());
System.out.println(xObject.getY());
System.out.println(xObject.getWidth());
System.out.println(xObject.getHeight());
System.out.println(xObject.getRotateAngle());
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
SearchCriteria criteria = new TextSearchCriteria("test", false);
// Specify search locations
doc.getSearchableObjects().setEmailSearchableObjects(EmailSearchableObjects.Subject
| EmailSearchableObjects.HtmlBody | EmailSearchableObjects.PlainTextBody);
// Note, search is performed only if you pass TextSearchCriteria
// instance to findWatermarks method
PossibleWatermarkCollection watermarks = doc.findWatermarks(criteria);
// Remove found text fragments
watermarks.clear();
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Set image search criteria
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH);
// Set text search criteria
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("Company Name");
// Find watermark
PossibleWatermarkCollection possibleWatermarks = doc.getSections().get_Item(0).getHeadersFooters()
.getByOfficeHeaderFooterType(OfficeHeaderFooterType.HeaderPrimary)
.findWatermarks(textSearchCriteria.or(imageSearchCriteria));
System.out.println(possibleWatermarks.getCount());
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (SlidesChart chart : doc.getSlides().get_Item(0).getCharts()) {
System.out.println(chart.getWidth());
System.out.println(chart.getHeight());
System.out.println(chart.getX());
System.out.println(chart.getY());
System.out.println(chart.getAlternativeText());
System.out.println(chart.getId());
System.out.println(chart.getName());
System.out.println(chart.getHyperlink(SlidesHyperlinkActionType.MouseClick));
System.out.println(chart.getHyperlink(SlidesHyperlinkActionType.MouseOver));
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get the size of content area
System.out.println(doc.getWorksheets().get_Item(0).getContentAreaHeight());
System.out.println(doc.getWorksheets().get_Item(0).getContentAreaWidth());
// Get the size of particular cell
System.out.println(doc.getWorksheets().get_Item(0).getColumnWidth(0));
System.out.println(doc.getWorksheets().get_Item(0).getRowHeight(0));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
System.out.println(doc.getSlideWidth());
System.out.println(doc.getSlideHeight());
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get dimensions
System.out.println(doc.getPages().get_Item(0).getWidth());
System.out.println(doc.getPages().get_Item(0).getHeight());
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop throught worksheets
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (CellsHeaderFooter headerFooter : worksheet.getHeadersFooters()) {
System.out.println(headerFooter.getHeaderFooterType());
for (CellsHeaderFooterSection section : headerFooter.getSections()) {
System.out.println(section.getSectionType());
if (section.getImage() != null) {
System.out.println(section.getImage().getWidth());
System.out.println(section.getImage().getHeight());
System.out.println(section.getImage().getBytes().length);
}
System.out.println(section.getScript());
}
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get header&footer font settings
System.out.println(doc.getHeaderFooter().getFont().getFamilyName());
System.out.println(doc.getHeaderFooter().getFont().getSize());
System.out.println(doc.getHeaderFooter().getFont().getBold());
System.out.println(doc.getHeaderFooter().getFont().getItalic());
System.out.println(doc.getHeaderFooter().getFont().getUnderline());
System.out.println(doc.getHeaderFooter().getFont().getStrikeout());
// Get text contained in headers&footers
System.out.println(doc.getHeaderFooter().getHeaderLeft());
System.out.println(doc.getHeaderFooter().getHeaderCenter());
System.out.println(doc.getHeaderFooter().getHeaderRight());
System.out.println(doc.getHeaderFooter().getFooterLeft());
System.out.println(doc.getHeaderFooter().getFooterCenter());
System.out.println(doc.getHeaderFooter().getFooterRight());
// Get text color
System.out.println(doc.getHeaderFooter().getTextColor().toArgb());
// Get header&footer margins
System.out.println(doc.getHeaderFooter().getFooterMargin());
System.out.println(doc.getHeaderFooter().getHeaderMargin());
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (CellsChart chart : doc.getWorksheets().get_Item(0).getCharts()) {
System.out.println(chart.getWidth());
System.out.println(chart.getHeight());
System.out.println(chart.getX());
System.out.println(chart.getY());
System.out.println(chart.getAlternativeText());
System.out.println(chart.getId());
System.out.println(chart.getName());
System.out.println(chart.getHyperlink());
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get slides
for (SlidesSlide slide : doc.getSlides()) {
if (slide.getImageFillFormat().getBackgroundImage() != null) {
System.out.println(slide.getImageFillFormat().getTileAsTexture());
System.out.println(slide.getImageFillFormat().getTransparency());
System.out.println(slide.getImageFillFormat().getBackgroundImage().getWidth());
System.out.println(slide.getImageFillFormat().getBackgroundImage().getHeight());
System.out.println(slide.getImageFillFormat().getBackgroundImage().getBytes().length);
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (CellsWorksheet worksheet : doc.getWorksheets()) {
if (worksheet.getBackgroundImage() != null) {
System.out.println(worksheet.getBackgroundImage().getWidth());
System.out.println(worksheet.getBackgroundImage().getHeight());
System.out.println(worksheet.getBackgroundImage().getBytes().length);
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get pages
for (DiagramPage page : doc.getPages()) {
System.out.println(page.getWidth());
System.out.println(page.getHeight());
System.out.println(page.getLeftMargin());
System.out.println(page.getRightMargin());
System.out.println(page.getTopMargin());
System.out.println(page.getBottomMargin());
System.out.println(page.getName());
System.out.println(page.isBackground());
System.out.println(page.isVisible());
if (page.getBackgroundPage() != null) {
System.out.println(page.getBackgroundPage().getName());
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load documemt
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get page setup
WordsPageSetup pageSetup = doc.getSections().get_Item(0).getPageSetup();
System.out.println(pageSetup.getWidth());
System.out.println(pageSetup.getHeight());
System.out.println(pageSetup.getTopMargin());
System.out.println(pageSetup.getRightMargin());
System.out.println(pageSetup.getBottomMargin());
System.out.println(pageSetup.getLeftMargin());
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
// Load document
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop through worksheets
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (CellsShape shape : worksheet.getShapes()) {
System.out.println(shape.getAutoShapeType());
System.out.println(shape.getMsoDrawingType());
System.out.println(shape.getText());
if (shape.getImage() != null) {
System.out.println(shape.getImage().getWidth());
System.out.println(shape.getImage().getHeight());
System.out.println(shape.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : shape.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(shape.getHyperlink());
System.out.println(shape.getId());
System.out.println(shape.getAlternativeText());
System.out.println(shape.getX());
System.out.println(shape.getY());
System.out.println(shape.getWidth());
System.out.println(shape.getHeight());
System.out.println(shape.getRotateAngle());
System.out.println(shape.isWordArt());
System.out.println(shape.getName());
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop through slides
for (SlidesSlide slide : doc.getSlides()) {
for (SlidesShape shape : slide.getShapes()) {
if (shape.getImage() != null) {
System.out.println(shape.getImage().getWidth());
System.out.println(shape.getImage().getHeight());
System.out.println(shape.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : shape.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(shape.getName());
System.out.println(shape.getAlternativeText());
System.out.println(shape.getX());
System.out.println(shape.getY());
System.out.println(shape.getWidth());
System.out.println(shape.getHeight());
System.out.println(shape.getRotateAngle());
System.out.println(shape.getText());
System.out.println(shape.getId());
System.out.println(shape.getShapeType());
System.out.println(shape.getZOrderPosition());
System.out.println(shape.getHyperlink(SlidesHyperlinkActionType.MouseClick));
System.out.println(shape.getHyperlink(SlidesHyperlinkActionType.MouseOver));
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop through pages
for (DiagramPage page : doc.getPages()) {
for (DiagramShape shape : page.getShapes()) {
if (shape.getImage() != null) {
System.out.println(shape.getImage().getWidth());
System.out.println(shape.getImage().getHeight());
System.out.println(shape.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : shape.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(shape.getName());
System.out.println(shape.getX());
System.out.println(shape.getY());
System.out.println(shape.getWidth());
System.out.println(shape.getHeight());
System.out.println(shape.getRotateAngle());
System.out.println(shape.getText());
System.out.println(shape.getId());
for (DiagramHyperlink hyperlink : shape.getHyperlinks()) {
System.out.println(hyperlink.getAddress());
System.out.println(hyperlink.getSubAddress());
System.out.println(hyperlink.getDescription());
}
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// loop through sections
for (WordsSection section : doc.getSections()) {
for (WordsShape shape : section.getShapes()) {
if (shape.getHeaderFooter() != null) {
System.out.println("In header/footer");
}
System.out.println(shape.getShapeType());
System.out.println(shape.getWidth());
System.out.println(shape.getHeight());
System.out.println(shape.isWordArt());
System.out.println(shape.getRotateAngle());
System.out.println(shape.getAlternativeText());
System.out.println(shape.getName());
System.out.println(shape.getX());
System.out.println(shape.getY());
System.out.println(shape.getText());
if (shape.getImage() != null) {
System.out.println(shape.getImage().getWidth());
System.out.println(shape.getImage().getHeight());
System.out.println(shape.getImage().getBytes().length);
}
for (FormattedTextFragment fragment : shape.getFormattedTextFragments()) {
System.out.println(fragment.getText());
System.out.println(fragment.getFont().getFamilyName());
System.out.println(fragment.getFont().getSize());
System.out.println(fragment.getForegroundColor().toArgb());
System.out.println(fragment.getBackgroundColor().toArgb());
}
System.out.println(shape.getHorizontalAlignment());
System.out.println(shape.getVerticalAlignment());
System.out.println(shape.getRelativeHorizontalPosition());
System.out.println(shape.getRelativeVerticalPosition());
System.out.println(shape.getHyperlink());
}
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create image watermark
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH);
// Add watermark to all visible headers of the first section
doc.getSections().get_Item(0).addWatermark(watermark);
watermark.close();
// Link all other headers&footers to corresponding headers&footers of the first section
for (int i = 1; i < doc.getSections().getCount(); i++) {
doc.getSections().get_Item(i).getHeadersFooters().linkToPrevious(true);
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Link footer for even numbered pages to corresponding footer in previous section
doc.getSections().get_Item(0).getHeadersFooters()
.getByOfficeHeaderFooterType(OfficeHeaderFooterType.FooterEven).setLinkedToPrevious(true);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// List all direct recipients
for (EmailAddress address : doc.getTo()) {
System.out.println(address.getAddress());
}
// List all CC recipients
for (EmailAddress address : doc.getCc()) {
System.out.println(address.getAddress());
}
// List all BCC recipients
for (EmailAddress address : doc.getBcc()) {
System.out.println(address.getAddress());
}
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Do something...
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Create watermak
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
DiagramShapeSettings shapeSettings = new DiagramShapeSettings();
shapeSettings.setLocked(true);
// Editing of the shape in Visio is forbidden
doc.addWatermark(watermark, shapeSettings);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Set the plain text body
doc.setBody("Test plain text body");
// Set the html body
doc.setHtmlBody("<html><body>Test html body</body></html>");
// Set the email subject
doc.setSubject("Test subject");
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop through shapes
for (SlidesShape shape : doc.getSlides().get_Item(0).getShapes()) {
if ("� Aspose 2016".equals(shape.getText())) {
shape.setAlternativeText("watermark");
shape.setRotateAngle(30);
shape.setX(200);
shape.setY(200);
shape.setWidth(400);
shape.setHeight(100);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Do not copy", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
watermark.setOpacity(0.5);
// Add watermark of any type first
doc.getPages().get_Item(0).addWatermark(watermark);
// Rasterize the first page
doc.getPages().get_Item(0).rasterize(100, 100, PdfImageConversionFormat.Png);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Initialize image or text watermark
TextWatermark watermark = new TextWatermark("Do not copy", new Font("Arial", 8));
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermark.setRotateAngle(45);
watermark.setSizingType(SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
watermark.setOpacity(0.5);
// Add watermark of any type first
doc.addWatermark(watermark);
// Rasterize all pages
doc.rasterize(100, 100, PdfImageConversionFormat.Png);
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove Annotation by index
doc.getPages().get_Item(0).getAnnotations().removeAt(0);
// Remove Annotation by reference
doc.getPages().get_Item(0).getAnnotations()
.remove(doc.getPages().get_Item(0).getAnnotations().get_Item(0));
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (PdfPage page : doc.getPages()) {
for (int i = page.getAnnotations().getCount() - 1; i >= 0; i--) {
for (FormattedTextFragment fragment : page.getAnnotations().get_Item(i)
.getFormattedTextFragments()) {
if ("Verdana".equals(fragment.getFont().getFamilyName())) {
page.getAnnotations().removeAt(i);
break;
}
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove Artifact by index
doc.getPages().get_Item(0).getArtifacts().removeAt(0);
// Remove Artifact by reference
doc.getPages().get_Item(0).getArtifacts().remove(doc.getPages().get_Item(0).getArtifacts().get_Item(0));
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (PdfPage page : doc.getPages()) {
for (int i = page.getArtifacts().getCount() - 1; i >= 0; i--) {
for (FormattedTextFragment fragment : page.getArtifacts().get_Item(i)
.getFormattedTextFragments()) {
if (fragment.getFont().getSize() > 42) {
page.getArtifacts().removeAt(i);
break;
}
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop through attachemnts
for (int i = doc.getAttachments().getCount() - 1; i >= 0; i--) {
EmailAttachment attachment = doc.getAttachments().get_Item(i);
// Remove all attached pdf files with a particular name
if (attachment.getName().contains("sample")
&& attachment.getDocumentInfo().getFileFormat() == FileFormat.Msg) {
doc.getAttachments().removeAt(i);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
PdfDocument doc = Document.load(PdfDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (int i = doc.getAttachments().getCount() - 1; i >= 0; i--) {
PdfAttachment attachment = doc.getAttachments().get_Item(i);
// Remove all attached pdf files with a particular name
if (attachment.getName().contains("EULA")
&& attachment.getDocumentInfo().getFileFormat() == FileFormat.Pdf) {
doc.getAttachments().removeAt(i);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
for (CellsWorksheet worksheet : doc.getWorksheets()) {
for (int i = worksheet.getAttachments().getCount() - 1; i >= 0; i--) {
CellsAttachment attachment = worksheet.getAttachments().get_Item(i);
if (attachment.isLink() && !new File(attachment.getSourceFullName()).exists() || // Linked file that is not
// available at this moment
attachment.getDocumentInfo().isEncrypted()) // Attached file protected with a password
{
// Remove the file if it meets at least one of the
// conditions above
worksheet.getAttachments().removeAt(i);
}
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove backgroung
doc.getSlides().get_Item(0).getImageFillFormat().setBackgroundImage(null);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
EmailDocument doc = Document.load(EmailDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Loop through objects
for (int i = doc.getEmbeddedObjects().getCount() - 1; i >= 0; i--) {
if (doc.getEmbeddedObjects().get_Item(i).getDocumentInfo().getFileFormat() == FileFormat.Jpeg) {
// Remove reference to the image from html body
String pattern = "<img[^>]*src=\"cid:" + doc.getEmbeddedObjects().get_Item(i).getContentId()
+ "\"[^>]*>";
doc.setHtmlBody(doc.getHtmlBody().replaceAll(pattern, ""));
// Remove the image
doc.getEmbeddedObjects().removeAt(i);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Replace hyperlink
doc.getWorksheets().get_Item(0).getCharts().get_Item(0).setHyperlink("https://www.aspose.com/");
doc.getWorksheets().get_Item(0).getShapes().get_Item(0).setHyperlink("https://www.groupdocs.com/");
// Remove hyperlink
doc.getWorksheets().get_Item(1).getCharts().get_Item(0).setHyperlink(null);
doc.getWorksheets().get_Item(1).getShapes().get_Item(0).setHyperlink(null);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
String oldUrl = "http://aspose.com/";
// Assign null to remove hyperlink
String newUrl = "http://groupdocs.com/";
for (SlidesSlide slide : doc.getSlides()) {
// Replace hyperlinks in shapes
for (SlidesShape shape : slide.getShapes()) {
replaceHyperlink(shape, SlidesHyperlinkActionType.MouseOver, oldUrl, newUrl);
replaceHyperlink(shape, SlidesHyperlinkActionType.MouseClick, oldUrl, newUrl);
// Replace hyperlinks in text fragments
for (FormattedTextFragment fragment : shape.getFormattedTextFragments()) {
replaceHyperlink((ISlidesHyperlinkContainer) fragment, SlidesHyperlinkActionType.MouseClick,
oldUrl, newUrl);
replaceHyperlink((ISlidesHyperlinkContainer) fragment, SlidesHyperlinkActionType.MouseOver,
oldUrl, newUrl);
}
}
// Replace hyperlinks in charts
for (SlidesChart chart : slide.getCharts()) {
replaceHyperlink(chart, SlidesHyperlinkActionType.MouseOver, oldUrl, newUrl);
replaceHyperlink(chart, SlidesHyperlinkActionType.MouseClick, oldUrl, newUrl);
}
}
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
//--------------------------- replaceHyperlink --------------------------
private static void replaceHyperlink(ISlidesHyperlinkContainer hyperlinkContainer, int hyperlinkActionType, String oldUrl, String newUrl) {
if (oldUrl.equals(hyperlinkContainer.getHyperlink(hyperlinkActionType))) {
hyperlinkContainer.setHyperlink(hyperlinkActionType, newUrl);
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
doc.getSearchableObjects().setSlidesSearchableObjects(SlidesSearchableObjects.Hyperlinks);
// Find all hyperlinks
PossibleWatermarkCollection watermarks = doc.findWatermarks();
// Remove found watermarks
watermarks.clear();
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Get shape
DiagramShape shape = doc.getPages().get_Item(0).getShapes().get_Item(0);
for (int i = shape.getHyperlinks().getCount() - 1; i >= 0; i--) {
if (shape.getHyperlinks().get_Item(i).getAddress().contains("http://someurl.com")) {
shape.getHyperlinks().removeAt(i);
}
}
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Replace hyperlink
doc.getSections().get_Item(0).getShapes().get_Item(0).setHyperlink("https://www.groupdocs.com/");
// Remove hyperlink
doc.getSections().get_Item(0).getShapes().get_Item(1).setHyperlink(null);
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove header
doc.getHeaderFooter().setHeaderCenter(null);
// Replace footer
doc.getHeaderFooter().setFooterCenter("Footer center");
doc.getHeaderFooter().getFont().setSize(19);
doc.getHeaderFooter().getFont().setFamilyName("Times New Roman");
doc.getHeaderFooter().setTextColor(Color.getBlack());
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
CellsDocument doc = Document.load(CellsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove shape by index
doc.getWorksheets().get_Item(0).getShapes().removeAt(0);
// Remove shape by reference
doc.getWorksheets().get_Item(0).getShapes()
.remove(doc.getWorksheets().get_Item(0).getShapes().get_Item(0));
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove shape by index
doc.getSlides().get_Item(0).getShapes().removeAt(0);
// Remove shape by reference
doc.getSlides().get_Item(0).getShapes().remove(doc.getSlides().get_Item(0).getShapes().get_Item(0));
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
DiagramDocument doc = Document.load(DiagramDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove shape by index
doc.getPages().get_Item(0).getShapes().removeAt(0);
// Remove shape by reference
doc.getPages().get_Item(0).getShapes().remove(doc.getPages().get_Item(0).getShapes().get_Item(0));
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java
WordsDocument doc = Document.load(WordsDocument.class, Common.mapSourceFilePath(FILE_PATH));
// Remove shape by index
doc.getSections().get_Item(0).getShapes().removeAt(0);
// Remove shape by reference
doc.getSections().get_Item(0).getShapes().remove(doc.getSections().get_Item(0).getShapes().get_Item(0));
// Save document
doc.save(Common.mapOutputFilePath(FILE_PATH));
doc.close();
Raw