Effortless Text & Image Watermarking
Great news for Node.js developers! GroupDocs.Watermark for Node.js via Java 24.3 has been released, and it supports adding customizable text or image watermarks to enrich your documents and protect confidential information. Check out these code snippets to see how these features work.
Adding text watermarks to your documents:
const groupdocsWatermark = require('@groupdocs/groupdocs.watermark')
function addATextWatermark() {
const documentPath = Constants.InDocumentPdf; // NOTE: Put the actual path for your document
const watermarker = new groupdocsWatermark.Watermarker(documentPath);
const watermark = new groupdocsWatermark.TextWatermark('top secret', new groupdocsWatermark.Font('Arial', 36));
watermark.setForegroundColor(groupdocsWatermark.Color.getRed());
watermark.setHorizontalAlignment(groupdocsWatermark.HorizontalAlignment.Center);
watermark.setVerticalAlignment(groupdocsWatermark.VerticalAlignment.Center);
watermarker.add(watermark);
watermarker.save(outputFilePath);
watermarker.close();
}
Source*
Adding image watermarks to your documents:
const groupdocsWatermark = require('@groupdocs/groupdocs.watermark')
function spreadsheetAddImageWatermarkIntoHeaderFooter() {
const documentPath = Constants.InSpreadsheetXlsx; // NOTE: Put the actual path for your document
// Create an instance of SpreadsheetLoadOptions
const loadOptions = new groupdocsWatermark.SpreadsheetLoadOptions();
// Create an instance of Watermarker
const watermarker = new groupdocsWatermark.Watermarker(documentPath, loadOptions);
// Create an instance of ImageWatermark
const watermark = new groupdocsWatermark.ImageWatermark(Constants.LogoPng); // NOTE: Put the actual path for your image
watermark.setVerticalAlignment(groupdocsWatermark.VerticalAlignment.Top);
watermark.setHorizontalAlignment(groupdocsWatermark.HorizontalAlignment.Center);
watermark.setSizingType(groupdocsWatermark.SizingType.ScaleToParentDimensions);
watermark.setScaleFactor(1);
// Create an instance of SpreadsheetWatermarkHeaderFooterOptions
const options = new groupdocsWatermark.SpreadsheetWatermarkHeaderFooterOptions();
options.setWorksheetIndex(0);
// Add watermark to worksheet's header or footer
watermarker.add(watermark, options);
// Save changes
watermarker.save(outputFilePath);
// Close watermarker
watermarker.close();
}
Source*
Unleash Watermark Search
In addition to adding watermarks, the Node.js document watermarking API includes another powerful feature: searching watermarks. You can locate and watermarks within documents using this feature, as highlighted in this code sample.
const groupdocsWatermark = require('@groupdocs/groupdocs.watermark')
function searchWatermarkWithCombinedSearch() {
const documentPath = Constants.InDocumentPdf; // NOTE: Put the actual path for your document
// Create watermarker
const watermarker = new groupdocsWatermark.Watermarker(documentPath);
// Define image search criteria
const imageSearchCriteria = new groupdocsWatermark.ImageDctHashSearchCriteria(Constants.LogoPng);
imageSearchCriteria.setMaxDifference(0.9);
// Define text search criteria
const textSearchCriteria = new groupdocsWatermark.TextSearchCriteria("Company Name");
// Define rotate angle search criteria
const rotateAngleSearchCriteria = new groupdocsWatermark.RotateAngleSearchCriteria(30, 60);
// Combine search criteria
const combinedSearchCriteria = imageSearchCriteria.or(textSearchCriteria).and(rotateAngleSearchCriteria);
// Search for possible watermarks
const possibleWatermarks = watermarker.search(combinedSearchCriteria);
// Output the results
console.log(`Found ${possibleWatermarks.getCount()} possible watermark(s).`);
// Close the watermarker
watermarker.close();
}
Source*
Are you looking to retrieve essential document details like file type, page count, and size? GroupDocs.Watermark for Node.js via Java makes it easy for you. Here is how you can perform this functionality in Node.js.
const groupdocsWatermark = require('@groupdocs/groupdocs.watermark')
function getDocumentInfoForLocalFile() {
const documentPath = Constants.InSourceDocx; // NOTE: Put the actual path for your document
const watermarker = new groupdocsWatermark.Watermarker(documentPath);
const documentInfo = watermarker.getDocumentInfo();
console.log('File type:', documentInfo.getFileType().toString());
console.log('Number of pages:', documentInfo.getPageCount());
console.log('Document size:', documentInfo.getSize(), 'bytes');
watermarker.close();
}
Source*
You can view the list of all new features, enhancements, and bug fixes introduced in this release by visiting GroupDocs.Watermark for Node.js via Java 24.3 Release Notes.