Learning The "J"

Home » JAVA Learning » Working with PDF » Writing PDF

Category Archives: Writing PDF

Writing PDF files


import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfOutline;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
import java.io.FileOutputStream;

public class WritingPDF extends PdfPageEventHelper {

    int i = 0;

    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\\Bookmarks.pdf"));

            writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
            document.open();

            document.add(new Paragraph("This is Page 1", new Font(Font.HELVETICA, 12)));
            document.newPage();
            document.add(new Paragraph("This is page 2", new Font(Font.HELVETICA, 12)));
            document.newPage();
            document.add(new Paragraph("This is page 3", new Font(Font.HELVETICA, 12)));
        } catch (Exception de) {
            de.printStackTrace();
        }

        document.close();
    }
    
}
Advertisements