Load document of specific format

The constructors Watermarker(String) and Watermarker(InputStream) can load a document of any supported format. When you’re loading a document, GroupDocs.Watermark automatically detects its type and creates an instance of the appropriate class. If document format is not supported, constructor throws UnsupportedFileTypeException. If you need specify the format of a document to load, you can use constructors with LoadOptions parameter.

The following examle demonstrates how to create a watermarker for the Spreadsheet document:

advanced_usage.loading_documents.LoadingDocumentOfSpecificFormat

// Constants.InSpreadsheetXlsx is an absolute or relative path to your document. Ex: "C:\\Docs\\spreadsheet.xlsx"
String filePath = Constants.InSpreadsheetXlsx;                                                                    
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();                                                
Watermarker watermarker = new Watermarker(filePath, loadOptions);                                                 
                                                                                                                  
// use watermarker methods to manage watermarks in the Spreadsheet document                                       
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 12));                             
                                                                                                                  
watermarker.add(watermark);                                                                                       
                                                                                                                  
watermarker.save(Constants.OutSpreadsheetXlsx);                                                                   
                                                                                                                  
watermarker.close();                                                                                            

Any supported format family has the specific LoadOptions descendant:

FormatLoadOptions descendant
DiagramDiagramLoadOptions
EmailEmailLoadOptions
ImageImageLoadOptions
GifImageGifImageLoadOptions
TiffImageTiffImageLoadOptions
PDFPdfLoadOptions
PresentationPresentationLoadOptions
SpreadsheetSpreadsheetLoadOptions
WordProcessingWordProcessingLoadOptions

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document watermarking App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to add watermark to PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Watermarking App.