GroupDocsGists
10/19/2017 - 11:25 AM

GetOriginalPdfDocWithWatermark.java

// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Java
try {
	// Setup GroupDocs.Viewer config
	ViewerConfig config = Utilities.getConfiguration();
	// Create image handler
	ViewerImageHandler imageHandler = new ViewerImageHandler(config);

	// Set PDF file options
	PdfFileOptions options = new PdfFileOptions();
	options.setGuid(fileName);

	// Set watermark properties
	Watermark watermark = new Watermark(watermarkText);
	watermark.setColor(Color.BLUE);
	watermark.setPosition(WatermarkPosition.Diagonal);
	watermark.setWidth(100f);

	options.setWatermark(watermark);

	// Get file as pdf with watermaks
	FileContainer container = imageHandler.getPdfFile(options);

	// Save file
	Utilities.saveAsFile(fileName, container.getStream(), ".pdf");
} catch (Exception exp) {
	System.out.println("Exception: " + exp.getMessage());
	exp.printStackTrace();
}