MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.Graphics2D;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
    public static void main(String[] args) throws Exception {
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("h.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Graphics2D graphics2D = cb.createGraphics(PageSize.A4.width(), PageSize.A4.height());
        graphics2D.drawString("Hello World", 36, 54);
        graphics2D.dispose();
        document.close();
    }
}