Last active
June 19, 2019 12:54
-
-
Save GroupDocsGists/317b2b4e2fa1cf17b7d15a8d43169540 to your computer and use it in GitHub Desktop.
GroupDocs.Watermark-for-Java 18.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.getShapes().getCount() - 1; i >= 0; i--) { | |
for (FormattedTextFragment fragment : worksheet.getShapes().get_Item(i) | |
.getFormattedTextFragments()) { | |
if ("Arial".equals(fragment.getFont().getFamilyName()) | |
&& Color.getRed().equals(fragment.getForegroundColor())) { | |
worksheet.getShapes().removeAt(i); | |
break; | |
} | |
} | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 and remove shapes from slides | |
for (SlidesSlide section : doc.getSlides()) { | |
for (int i = section.getShapes().getCount() - 1; i >= 0; i--) { | |
for (FormattedTextFragment fragment : section.getShapes().get_Item(i) | |
.getFormattedTextFragments()) { | |
if ("Arial".equals(fragment.getFont().getFamilyName()) | |
&& Color.getRed().equals(fragment.getForegroundColor())) { | |
section.getShapes().removeAt(i); | |
break; | |
} | |
} | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 pages and remove shapes with particular text formatting | |
for (DiagramPage section : doc.getPages()) | |
{ | |
for (int i = section.getShapes().getCount() - 1; i >= 0; i--) | |
{ | |
for (FormattedTextFragment fragment : section.getShapes().get_Item(i).getFormattedTextFragments()) | |
{ | |
if ("Arial".equals(fragment.getFont().getFamilyName()) && Color.getRed().equals(fragment.getForegroundColor())) | |
{ | |
section.getShapes().removeAt(i); | |
break; | |
} | |
} | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
for (WordsSection section : doc.getSections()) { | |
for (int i = section.getShapes().getCount() - 1; i >= 0; i--) { | |
for (FormattedTextFragment fragment : section.getShapes().get_Item(i) | |
.getFormattedTextFragments()) { | |
if ("Arial".equals(fragment.getFont().getFamilyName()) | |
&& Color.getRed().equals(fragment.getForegroundColor())) { | |
section.getShapes().removeAt(i); | |
break; | |
} | |
} | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 search criteria | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("Test watermark"); | |
// Call findWatermarks method for a worksheet | |
PossibleWatermarkCollection possibleWatermarks = doc.getWorksheets().get_Item(0) | |
.findWatermarks(textSearchCriteria.or(imageSearchCriteria)); | |
// Remove all found watermarks | |
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--) { | |
possibleWatermarks.removeAt(i); | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 search criteria | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("This is a test watermark"); | |
PossibleWatermarkCollection possibleWatermarks = doc.getPages().get_Item(0) | |
.findWatermarks(imageSearchCriteria.or(textSearchCriteria)); | |
// Remove all found watermarks | |
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--) { | |
possibleWatermarks.removeAt(i); | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 search criteria | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("This is test watermark"); | |
// Call findWatermarks method for a section | |
PossibleWatermarkCollection possibleWatermarks = doc.getSections().get_Item(0) | |
.findWatermarks(textSearchCriteria.or(imageSearchCriteria)); | |
// Remove all found watermarks | |
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--) { | |
possibleWatermarks.removeAt(i); | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 search criteria | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("This is test watermark"); | |
// Call findWatermarks method for a slide | |
PossibleWatermarkCollection possibleWatermarks = doc.getSlides().get_Item(0) | |
.findWatermarks(textSearchCriteria.or(imageSearchCriteria)); | |
// Remove all found watermarks | |
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--) { | |
possibleWatermarks.removeAt(i); | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 search criteria | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("Test watermark"); | |
// Call findWatermarks method for the first page | |
PossibleWatermarkCollection possibleWatermarks = doc.getPages().get_Item(0) | |
.findWatermarks(textSearchCriteria.or(imageSearchCriteria)); | |
// Remove all found watermarks | |
possibleWatermarks.clear(); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 background | |
doc.getWorksheets().get_Item(0).setBackgroundImage(null); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 XObject by index | |
doc.getPages().get_Item(0).getXObjects().removeAt(0); | |
// Remove XObject by reference | |
doc.getPages().get_Item(0).getXObjects().remove(doc.getPages().get_Item(0).getXObjects().get_Item(0)); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.getXObjects().getCount() - 1; i >= 0; i--) { | |
for (FormattedTextFragment fragment : page.getXObjects().get_Item(i) | |
.getFormattedTextFragments()) { | |
if (Color.getRed().equals(fragment.getForegroundColor())) { | |
page.getXObjects().removeAt(i); | |
break; | |
} | |
} | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
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(); | |
// Set shape image | |
for (CellsShape shape : doc.getWorksheets().get_Item(0).getShapes()) { | |
if (shape.getImage() != null) { | |
shape.setImage(new CellsWatermarkableImage(imageBytes)); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 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(); | |
// Set shape image | |
for (SlidesShape shape : doc.getSlides().get_Item(0).getShapes()) { | |
if (shape.getImage() != null) { | |
shape.setImage(new SlidesWatermarkableImage(imageBytes)); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set image 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(); | |
// Set shape image | |
for (DiagramShape shape : doc.getPages().get_Item(0).getShapes()) { | |
if (shape.getImage() != null) { | |
shape.setImage(new DiagramWatermarkableImage(imageBytes)); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set shape text | |
for (SlidesShape shape : doc.getSlides().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.setText("� GroupDocs 2017"); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 shape text | |
for (CellsShape shape : doc.getWorksheets().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.setText("� GroupDocs 2017"); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set shape text | |
for (DiagramShape shape : doc.getPages().get_Item(0).getShapes()) { | |
if (shape.getText() != null && shape.getText().contains("� Aspose 2016")) { | |
shape.setText("� GroupDocs 2017"); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Replace shape text | |
for (SlidesShape shape : doc.getSlides().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.getFormattedTextFragments().clear(); | |
shape.getFormattedTextFragments().add("� GroupDocs 2017", | |
new Font("Calibri", 19, FontStyle.Bold), Color.getRed(), Color.getAqua()); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set shape text | |
for (SlidesShape shape : doc.getSlides().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.getFormattedTextFragments().clear(); | |
shape.getFormattedTextFragments().add("� GroupDocs 2017", | |
new Font("Calibri", 19, FontStyle.Bold), Color.getRed(), Color.getAqua()); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 shape text | |
for (CellsShape shape : doc.getWorksheets().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.getFormattedTextFragments().clear(); | |
shape.getFormattedTextFragments().add("� GroupDocs 2017", | |
new Font("Calibri", 19, FontStyle.Bold), Color.getRed(), Color.getAqua()); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set shape text | |
for (DiagramShape shape : doc.getPages().get_Item(0).getShapes()) { | |
if (shape.getText() != null && shape.getText().contains("� Aspose 2016")) { | |
shape.getFormattedTextFragments().clear(); | |
shape.getFormattedTextFragments().add("� GroupDocs 2017", | |
new Font("Calibri", 19, FontStyle.Bold), Color.getRed(), Color.getAqua()); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Consider only the attached images | |
doc.getSearchableObjects().setCellsSearchableObjects(CellsSearchableObjects.AttachedImages); | |
// Specify sample image to compare document images with | |
ImageSearchCriteria criteria = new ImageDctHashSearchCriteria("D:\\watermark.jpg"); | |
// Search for similar images | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(criteria); | |
// Remove found image watermarks | |
possibleWatermarks.clear(); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Consider only the attached images | |
doc.getSearchableObjects().setPdfSearchableObjects(PdfSearchableObjects.AttachedImages); | |
// Specify sample image to compare document images with | |
ImageSearchCriteria criteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
// Search for similar images | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(criteria); | |
// Remove found image watermarks | |
possibleWatermarks.clear(); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 image 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(); | |
// Set background image | |
CellsChart chart = doc.getWorksheets().get_Item(0).getCharts().get_Item(0); | |
chart.getImageFillFormat().setBackgroundImage(new CellsWatermarkableImage(imageBytes)); | |
chart.getImageFillFormat().setTransparency(0.5); | |
chart.getImageFillFormat().setTileAsTexture(true); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set image 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(); | |
// Set background image | |
SlidesImageFillFormat imageFillFormat = doc.getSlides().get_Item(0).getCharts().get_Item(0) | |
.getImageFillFormat(); | |
imageFillFormat.setBackgroundImage(new SlidesWatermarkableImage(imageBytes)); | |
imageFillFormat.setTransparency(0.5); | |
imageFillFormat.setTileAsTexture(true); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 image 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(); | |
// Set background | |
for (CellsShape shape : doc.getWorksheets().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.getImageFillFormat().setBackgroundImage(new CellsWatermarkableImage(imageBytes)); | |
shape.getImageFillFormat().setTransparency(0.5); | |
shape.getImageFillFormat().setTileAsTexture(true); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Set image 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(); | |
// Set background | |
for (SlidesShape shape : doc.getSlides().get_Item(0).getShapes()) { | |
if ("� Aspose 2016".equals(shape.getText())) { | |
shape.getImageFillFormat().setBackgroundImage(new SlidesWatermarkableImage(imageBytes)); | |
shape.getImageFillFormat().setTransparency(0.5); | |
shape.getImageFillFormat().setTileAsTexture(true); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
// Get image | |
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(); | |
// Load document | |
SlidesDocument doc = Document.load(SlidesDocument.class, Common.mapSourceFilePath(FILE_PATH)); | |
// Get slide and update background | |
SlidesSlide slide = doc.getSlides().get_Item(0); | |
slide.getImageFillFormat().setBackgroundImage(new SlidesWatermarkableImage(imageBytes)); | |
slide.getImageFillFormat().setTileAsTexture(true); | |
slide.getImageFillFormat().setTransparency(0.5); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String FILE_PATH = "sample.xlsx"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String FILE_PATH = "sample.pdf"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String FILE_PATH = "sample.pptx"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String FILE_PATH = "sample.msg"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String FILE_PATH = "sample_with_watermark.docx"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
// Update shape properties | |
for (CellsShape shape : doc.getWorksheets().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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
MultiframeImageDocument doc = Document.load(MultiframeImageDocument.class, | |
Common.mapSourceFilePath(FILE_PATH)); | |
// Initialize text or image watermark | |
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19)); | |
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH); | |
// Add watermark to the first frame | |
doc.getFrames().get_Item(0).addWatermark(watermark); | |
doc.getFrames().get_Item(0).addWatermark(imageWatermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String FILE_PATH = "sample.gif"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Use path to an image as constructor parameter | |
ImageWatermark watermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH); | |
// Add watermark to the document | |
doc.addWatermark(watermark); | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
watermark.close(); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(PPT_FILE_PATH)); | |
FileInputStream watermarkInputStream = new FileInputStream(Common.WATERMARK_IMAGE_PATH); | |
// Use stream containing an image as constructor parameter | |
ImageWatermark watermark = new ImageWatermark(watermarkInputStream); | |
// Add watermark to the document | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(PPT_FILE_PATH)); | |
watermark.close(); | |
watermarkInputStream.close(); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(PNG_FILE_PATH)); | |
Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic); | |
TextWatermark watermark = new TextWatermark("Test watermark", font); | |
// Set watermark properties | |
watermark.setForegroundColor(Color.getRed()); | |
watermark.setBackgroundColor(Color.getBlue()); | |
watermark.setTextAlignment(TextAlignment.Right); | |
watermark.setOpacity(0.5); | |
// Add watermark | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(PNG_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(XLS_FILE_PATH)); | |
Font font = new Font("Calibri", 8); | |
TextWatermark watermark = new TextWatermark("Test watermark", font); | |
watermark.setHorizontalAlignment(HorizontalAlignment.Right); | |
watermark.setVerticalAlignment(VerticalAlignment.Top); | |
watermark.setSizingType(SizingType.ScaleToParentDimensions); | |
watermark.setScaleFactor(0.5); | |
// Set rotation angle | |
watermark.setRotateAngle(RotationAngle); | |
// Add watermark | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(XLS_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
Font font = new Font("Times New Roman", 8); | |
TextWatermark watermark = new TextWatermark("Test watermark", font); | |
// Set watermark coordinates | |
watermark.setX(30); | |
watermark.setY(40); | |
// Set watermark size | |
watermark.setWidth(100); | |
watermark.setHeight(40); | |
// Add watermark | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(PPT_FILE_PATH)); | |
// Initialize text watermark | |
TextWatermark textWatermark = new TextWatermark("Protected image", new Font("Arial", 8)); | |
textWatermark.setHorizontalAlignment(HorizontalAlignment.Center); | |
textWatermark.setVerticalAlignment(VerticalAlignment.Center); | |
textWatermark.setRotateAngle(45); | |
textWatermark.setSizingType(SizingType.ScaleToParentDimensions); | |
textWatermark.setScaleFactor(1); | |
// Initialize image watermark | |
ImageWatermark imageWatermark = new ImageWatermark(Common.WATERMARK_IMAGE_PATH); | |
imageWatermark.setHorizontalAlignment(HorizontalAlignment.Center); | |
imageWatermark.setVerticalAlignment(VerticalAlignment.Center); | |
imageWatermark.setRotateAngle(-45); | |
imageWatermark.setSizingType(SizingType.ScaleToParentDimensions); | |
imageWatermark.setScaleFactor(1); | |
// Find all images in a document | |
WatermarkableImageCollection images = doc.findImages(); | |
for (int i = 0; i < images.getCount(); i++) { | |
if (images.get_Item(i).getWidth() > 100 && images.get_Item(i).getHeight() > 100) { | |
if (i % 2 == 0) { | |
images.get_Item(i).addWatermark(textWatermark); | |
} else { | |
images.get_Item(i).addWatermark(imageWatermark); | |
} | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(PPT_FILE_PATH)); | |
imageWatermark.close(); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Create watermark and set font | |
Font font = new Font("Calibri", 42); | |
TextWatermark watermark = new TextWatermark("Test watermark", font); | |
watermark.setHorizontalAlignment(HorizontalAlignment.Right); | |
watermark.setVerticalAlignment(VerticalAlignment.Bottom); | |
watermark.getMargins().setRight(0.1); | |
watermark.getMargins().setBottom(0.2); | |
// Add watermark | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
Font font = new Font("Calibri", 12); | |
// Create TextWatermark and set its properties | |
TextWatermark watermark = new TextWatermark("Test watermark", font); | |
watermark.setHorizontalAlignment(HorizontalAlignment.Right); | |
watermark.setVerticalAlignment(VerticalAlignment.Bottom); | |
// Set relative margins. Margin value will be interpreted as a | |
// portion of appropriate parent dimension. | |
// If this type is chosen, margin value must be between 0.0 and 1.0. | |
watermark.getMargins().setMarginType(MarginType.RelativeToParentDimensions); | |
watermark.getMargins().setRight(0.1); | |
watermark.getMargins().setBottom(0.2); | |
// Add watermark | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Create TextWatermark and set its properties | |
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); | |
watermark.setRotateAngle(45); | |
watermark.setForegroundColor(Color.getRed()); | |
watermark.setBackgroundColor(Color.getAqua()); | |
// Add watermark considering parent margins | |
watermark.setConsiderParentMargins(true); | |
// Add watermark | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
Font font = new Font("Times New Roman", 12); | |
TextWatermark watermark = new TextWatermark("Test watermark", font); | |
// Set sizing type | |
watermark.setSizingType(SizingType.ScaleToParentDimensions); | |
// Set watermark scale | |
watermark.setScaleFactor(0.5); | |
// Add watermak | |
doc.addWatermark(watermark); | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Find watermark with particular text search criteria | |
PossibleWatermarkCollection watermarks = doc | |
.findWatermarks(new TextSearchCriteria(Pattern.compile("someurl\\.com"))); | |
for (int i = watermarks.getCount() - 1; i >= 0; i--) { | |
// Ensure that only hyperlinks will be removed | |
if (HyperlinkPossibleWatermark.class.isInstance(watermarks.get_Item(i))) { | |
// Output the full url of the hyperlink | |
System.out.println(watermarks.get_Item(i).getText()); | |
// Remove hyperlink from the document | |
watermarks.removeAt(i); | |
} | |
} | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(); | |
// Remove possible watermark at the specified index from the | |
// document. | |
possibleWatermarks.removeAt(0); | |
// Remove specified possible watermark from the document. | |
// possibleWatermarks.remove(possibleWatermarks.get_Item(0)); | |
// Save document | |
doc.save(Common.mapOutputFilePath(DOC_FILE_PATH)); | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Initialize criteria with the image | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
// Set maximum allowed difference between images | |
imageSearchCriteria.setMaxDifference(0.1); | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(imageSearchCriteria); | |
System.out.println(possibleWatermarks.get_Item(0).getHeight()); | |
// ... | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Get possible watermarks using findWatermarks method | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(); | |
for (PossibleWatermark possibleWatermark : possibleWatermarks) { | |
if (possibleWatermark.getImageData() != null) { | |
System.out.println(possibleWatermark.getImageData().length); | |
} | |
System.out.println(possibleWatermark.getText()); | |
System.out.println(possibleWatermark.getX()); | |
System.out.println(possibleWatermark.getY()); | |
System.out.println(possibleWatermark.getRotateAngle()); | |
System.out.println(possibleWatermark.getWidth()); | |
System.out.println(possibleWatermark.getHeight()); | |
} | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
// Set searchable objects | |
SearchableObjects searchableObjects = new SearchableObjects(); | |
searchableObjects.setWordsSearchableObjects( | |
WordsSearchableObjects.Hyperlinks | WordsSearchableObjects.Shapes | WordsSearchableObjects.Text); | |
searchableObjects.setCellsSearchableObjects(CellsSearchableObjects.HeadersFooters); | |
searchableObjects.setSlidesSearchableObjects( | |
SlidesSearchableObjects.SlidesBackgrounds | SlidesSearchableObjects.Shapes); | |
searchableObjects.setDiagramSearchableObjects(DiagramSearchableObjects.None); | |
searchableObjects.setPdfSearchableObjects(PdfSearchableObjects.All); | |
// Set default searchable objects | |
Document.setDefaultSearchableObjects(searchableObjects); | |
// Loop through files | |
File folder = new File(Common.STORAGE_PATH.toString()); | |
File[] listOfFiles = folder.listFiles(); | |
for (File file : listOfFiles) { | |
if (file.isFile()) { | |
Document doc = Document.load(file.getAbsolutePath()); | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(); | |
System.out.println(possibleWatermarks.getCount()); | |
// The code for working with found watermarks goes here. | |
doc.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(PDF_FILE_PATH)); | |
// Search for hyperlinks only. | |
doc.getSearchableObjects().setPdfSearchableObjects(PdfSearchableObjects.Hyperlinks); | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(); | |
System.out.println(possibleWatermarks.getCount()); | |
// The code for working with found watermarks goes here. | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Create image seach criteria | |
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(Common.WATERMARK_IMAGE_PATH); | |
imageSearchCriteria.setMaxDifference(0.9); | |
// Create text seach criteria | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("Test watermark"); | |
// Create rotate angle search criteria | |
RotateAngleSearchCriteria rotateAngleSearchCriteria = new RotateAngleSearchCriteria(30, 60); | |
SearchCriteria combinedSearchCriteria = imageSearchCriteria.or(textSearchCriteria) | |
.and(rotateAngleSearchCriteria); | |
// Find watermarks | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(combinedSearchCriteria); | |
System.out.println(possibleWatermarks.getCount()); | |
// ... | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Create search criteria for formatted text | |
TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria(); | |
criteria.setForegroundColorRange(new ColorRange()); | |
criteria.getForegroundColorRange().setMinHue(-5); | |
criteria.getForegroundColorRange().setMaxHue(10); | |
criteria.getForegroundColorRange().setMinBrightness(0.01f); | |
criteria.getForegroundColorRange().setMaxBrightness(0.99f); | |
criteria.setBackgroundColorRange(new ColorRange()); | |
criteria.getBackgroundColorRange().setEmpty(true); | |
criteria.setFontName("Arial"); | |
criteria.setMinFontSize(19); | |
criteria.setMaxFontSize(42); | |
criteria.setFontBold(false); | |
PossibleWatermarkCollection watermarks = doc.findWatermarks(criteria); | |
// ... | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
Pattern pattern = Pattern.compile("� \\d{4}"); | |
// Search by regular expression | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria(pattern); | |
// Find possible watermarks using regular expression | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(textSearchCriteria); | |
// ... | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
Document doc = Document.load(Common.mapSourceFilePath(DOC_FILE_PATH)); | |
// Search by exact string | |
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("Copyright 2017"); | |
// Find all possible watermarks containing some specific text | |
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(textSearchCriteria); | |
// ... | |
doc.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java | |
private final static String PNG_FILE_PATH = "sample.png"; | |
private final static String DOC_FILE_PATH = "sample.docx"; | |
private final static String PPT_FILE_PATH = "sample.pptx"; | |
private final static String XLS_FILE_PATH = "sample.xlsx"; | |
private final static String PDF_FILE_PATH = "sample.pdf"; | |
public static final String WATERMARK_IMAGE_PATH = getProjectBaseDir().resolve("Data/watermark.jpg").toString(); | |
public static final String ATTACHMENTS_PATH = getProjectBaseDir().resolve("Data/Attachments/").toString(); | |
public static String LICENSE_PATH = "D:\\GroupDocs.Total.Java.lic"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment