Java

Generate PDF in Java using iText

First of all download iText.

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
 
public class pdf {
 
    public static void main(String[] args) {
        try (OutputStream pdffile = new FileOutputStream(new File("/home/username/Documents/test.pdf"))) {
            Document document = new Document();
            PdfWriter.getInstance(document, pdffile);
            document.open();
            document.add(new Paragraph("Hello, World!"));
            document.close();
            pdffile.close();
        }
        catch (DocumentException | IOException e) {
            System.err.println(e.getMessage());
        }
    }
}