Is it possible to print date and time in pdf in footer programmatically using Aspose PDF for Java API.
You can use TextStamp in order to add date and time or any other text in the footer of the PDF document. Please check below article(s) the API documentation:
@asad.ali Was trying to watermark using the code snippet attached. in cover page it is showing the watermark in Diagonal fashion, in all other pages in horizontal.sample screenshot of watermark also attached.
Wanted watermark in Diagonal fashion in all pages.Any suggestions?
details.zip (79.5 KB)
Can you please also share the sample source PDF for our reference? We will test the scenario in our environment and address it accordingly.
Instead of WatermarkArtifact, you can still use TextStamp in order to add watermark like below:
Document doc = new Document(dataDir + "Sample-pdf.pdf");
// Create a formatted text
com.aspose.pdf.facades.FormattedText formattedText = new com.aspose.pdf.facades.FormattedText("Confidential Document", java.awt.Color.RED, com.aspose.pdf.facades.FontStyle.Courier, com.aspose.pdf.facades.EncodingType.Identity_h, true, 40.0F);
// Create watermark artifact and set its properties
TextStamp artifact = new TextStamp(formattedText);
artifact.setHorizontalAlignment(HorizontalAlignment.Center);
artifact.setVerticalAlignment(VerticalAlignment.Center);
artifact.setRotateAngle(25);
artifact.setOpacity(0.5);
artifact.setBackground(false);
java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String fdate = dateFormat.format(date);
TextStamp textStamp = new TextStamp(fdate);
// Add watermark to all pages of the PDF
PageCollection pdfPageCollection = doc.getPages();
for (Page pdfPage : pdfPageCollection) {
pdfPage.addStamp(artifact);
}
// Set properties for the date stamp
textStamp.setBottomMargin(10);
textStamp.setHorizontalAlignment(HorizontalAlignment.Center);
textStamp.setVerticalAlignment(VerticalAlignment.Bottom);
// Add footer with the current date on all pages
for (Page page : pdfPageCollection) {
page.addStamp(textStamp);
}
doc.save(dataDir + "watermarked.pdf");
watermarked.pdf (48.7 KB)
Looks like an issue in WatermarkArtifact Class. It is logged as PDFJAVA-43582 in our issue tracking system for the sake of rectification. We will let you know as well once it is resolved. We apologize for the inconvenience caused.