Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Adding stamp to existing pdf overrides pdf

$
0
0
Hello

I was able to generate a PDF file form PCL with header and footer, no I want to add an image as a stamp for each page. However, when I try to add the stamp it overrides the PDF with text and header and footer and just gives me blank pages with stamp in them. I am adding the stamp after generating the PDF since stamp is added from Document object while I added the text, header and footer from PDF object.

Here is a snippet of my code that generates the PDF and tries to add stamp.

        Pdf pdf = new Pdf();
pdf.bindPCL(pclFilePath);
String imageFileType           = properties.getProperty("IMAGE_FILE_TYPE");
String headerImageFullPath     = properties.getProperty("HEADER_FULL_PATH");
String footerImageFullPath     = properties.getProperty("FOOTER_FULL_PATH");
int fileTypeValue = imageFileType.equalsIgnoreCase("PNG") ? ImageFileType.Png : ((imageFileType.equalsIgnoreCase("JPEG") || imageFileType.equalsIgnoreCase("JPG")) ? ImageFileType.Jpeg : ImageFileType.Unknown);
HeaderFooter header = new HeaderFooter();
HeaderFooter footer = new HeaderFooter();
Image headerImage = new Image();
headerImage.getImageInfo().setImageFileType(fileTypeValue);
headerImage.getImageInfo().setFile(headerImageFullPath);
headerImage.getImageInfo().setAlignment(AlignmentType.Center);
header.getParagraphs().add(headerImage);
Image footerImage = new Image();
footerImage.getImageInfo().setImageFileType(fileTypeValue);
footerImage.getImageInfo().setFile(footerImageFullPath);
footerImage.getImageInfo().setAlignment(AlignmentType.Center);
footer.getParagraphs().add(footerImage);
for(int i = 0; i < pdf.getSections().size(); i++) {
Section sec = pdf.getSections().get_Item(i);
sec.setOddHeader(header);
sec.setEvenHeader(header);
sec.setOddFooter(footer);
sec.setEvenFooter(footer);
}
and for the adding of stamp

Document pdf = new Document(pdfFilePath);
ImageStamp imageStamp = new ImageStamp("c:\\temp\\bg.png");
imageStamp.setBackground(true);
imageStamp.setHorizontalAlignment(HorizontalAlignment.Center);
imageStamp.setVerticalAlignment(VerticalAlignment.Center);
for (int Page_counter = 1; Page_counter <= pdf.getPages().size(); Page_counter++) {
    Page page = pdf.getPages().get_Item(Page_counter);
    page.addStamp(imageStamp);
}
pdf.save("c:\\temp\\test.pdf");

What am I doing wrong, I need to be able to add a background image to the pdf.

Thanks

Viewing all articles
Browse latest Browse all 3131

Trending Articles