import java.io.FileOutputStream;
import java.util.HashMap;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
*/
public class Foxit2{
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
* @param args no arguments needed
*/
public static void main(String[] args) {
System.out.println("Add watermarks and pagenumbers");
try {
// we create a reader for a certain document
PdfReader reader = new PdfReader("application.pdf");
int n = reader.getNumberOfPages();
// we create a stamper that will copy the document to a new file
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("app2.pdf"));
// adding some metadata
// adding content to each page
int i = 0;
PdfContentByte under;
PdfContentByte over;
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
while (i < n) {
i++;
// watermark under the existing page
under = stamp.getUnderContent(i);
under.setFontAndSize(bf, 12);
if (i==1) {
//last name
under.showTextAligned(PdfContentByte.ALIGN_LEFT, args[0], 50.0f,640.0f, 0);
}
// text over the existing page
over = stamp.getOverContent(i);
}
// adding an extra page
over = stamp.getOverContent(1);
// closing PdfStamper will generate the new PDF file
stamp.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
bruno <[EMAIL PROTECTED]> wrote:
murthy gandikota wrote:
> Hi Bruno
> Many thanks for your response.
No problem, you're welcome.
> I was able to make it work using the PdfStamper tutorial. If anyone is
> interested I can post the code.
It wouldn't hurt to post a small sample to the mailing list for future
reference.
br,
Bruno
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2ยข/min with Yahoo! Messenger with Voice.
