Preview:
/*
 * This Java source file was generated by the Gradle 'init' task.
 */
package gradleproject2;

import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;

public class App {

    public String getGreeting() {
        return "Hello World!";
    }

    public static void main(String[] args) throws IOException {
        // System.out.println(new App().getGreeting());

        //Creating PDF document object 
        PDDocument document = new PDDocument();

        for (int i = 0; i < 10; i++) {
            //Creating a blank page 
            PDPage blankPage = new PDPage();

            PDPageContentStream contentStream = new PDPageContentStream(document, blankPage);

            contentStream.setFont(new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD), 12);

            // Add text to the page
            contentStream.beginText();

            contentStream.newLineAtOffset(100, 700);

            contentStream.showText("Hello World, how are you !");

            contentStream.endText();

            //Adding the blank page to the document
            document.addPage(blankPage);
            contentStream.close();
        }

        //Saving the document
        document.save("C:/Users/chachou/Desktop/test java/javageneratepdf.pdf");
        System.out.println("PDF created");
        
      
        //Closing the document
        document.close();
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter