MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

public class MainClass {

    public static void main(String[] args) throws Exception {
        PdfReader reader = new PdfReader("HelloWorldRead.pdf");
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("HelloWorldStamper.pdf"));
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        PdfContentByte over;
        int total = reader.getNumberOfPages() + 1;
        for (int i = 1; i < total; i++) {
            over = stamper.getOverContent(i);
            over.beginText();
            over.setFontAndSize(bf, 18);
            over.setTextMatrix(30, 30);
            over.showText("page " + i);
            over.endText();
            over.setRGBColorStroke(0xFF, 0x00, 0x00);
            over.setLineWidth(5f);
            over.ellipse(250, 450, 350, 550);
            over.stroke();
        }
        stamper.close();
    }

}