0

The requirement is to stamp image/logo to pdf. PDfs are present in content management system.There are certain pdfs which are created from PPT and also of different size. Hence Stamping image code is working for certain pdfs and not working for pdfs like which are created from ppt or of different size.

The below code which i used for logo stamping.

try {
    PdfReader pdfReader = new PdfReader("C:/Users/298995/workspace/ChangeDocumentLogo/bin/pdf/RMWCS_RFBICMOS.pdf");

    PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("NANOSSHSSLFS-NewLogo3.pdf"));
    System.out.println("start3");

    Image image = Image.getInstance("C:/Users/298995/workspace/ChangeDocumentLogo/bin/pdf/nxp.png");

    for(int i=1; i<= pdfReader.getNumberOfPages(); i++){
        pdfReader.getPageSize(i);
        PdfContentByte content = pdfStamper.getOverContent(i);
        image.setAbsolutePosition(10f,755f);
        content.addImage(image);
    }

    pdfStamper.close();

} catch (IOException e) {
    e.printStackTrace();
} catch (DocumentException e) {
    e.printStackTrace();
}
mkl
  • 90,588
  • 15
  • 125
  • 265
Salu Kumar Sahoo
  • 11
  • 1
  • 1
  • 5
  • You use hard coded coordinates. For differing page sizes this certainly will fail every once in a while. Consider using coordinates relative to the page size. – mkl Feb 11 '16 at 15:48
  • What all contents does it support? Is there a way in iText to see if a PDF Doc is unsupported? – Salu Kumar Sahoo Feb 12 '16 at 15:37
  • This question is a duplicate of [How to add an image watermark to a PDF file?](http://developers.itextpdf.com/question/how-add-image-watermark-pdf-file) As @mkl already indicated, the absolute position `(10f, 755f)` isn't valid for every PDF you'll encounter. Please read [the documentation](http://developers.itextpdf.com/) before you ask a question that has already been answered so many times before. – Bruno Lowagie Feb 12 '16 at 16:27

0 Answers0