Adding text to an existing pdf that closes with itextsharp

Hi I am creating a PDF using itextsharp. Now my requirement is to add more text to an existing pdf. Is it possible, if so, how can I do this?

Thanks Dipa

+4
source share
1 answer

Yes, with certain limitations.

It is difficult, but not impossible, to determine what is already on the existing page.

If all you want to do is add “page X of Y” to the lower left corner of all your pages, simply .

PdfReader reader = new PdfReader( inPath );
PdfStamper stamper = new PdfStamper( reader, new FileOutputStream( outPath ) );
BaseFont font = BaseFont.createFont(); // Helvetica, WinAnsiEncoding
for (int i = 0; i < reader.getNumberOfPages(); ++i) {
  PdfContentByte overContent = stamper.getOverContent( i + 1 );
  overContent.saveState();
  overContent.beginText();
  overContent.setFontAndSize( font, 10.0f );
  overContent.setTextMatrix( xLoc, yLoc );
  overContent.showText( "Page " + (i + 1) + " of " + reader.getNumberOfPages() );
  overContent.endText();
  overContent.restoreState();
}
stamper.close();

A large watermark is not much more complicated. Adding things to a PDF in one or more predefined locations is feasible.

" ". . PDF .

, , . , .

+9

All Articles