Java:pdf < 2K - UHD >

<dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.23</version> </dependency> If you're using Gradle, add the following dependency to your build.gradle :

// Create a content stream and write text try (PDPageContentStream contents = new PDPageContentStream(document, page)) { // Set font and font size contents.setFont(PDType1Font.HELVETICA_BOLD, 24); java:pdf

public class PdfGenerator {

implementation 'org.apache.pdfbox:pdfbox:2.0.23' &lt;dependency&gt; &lt;groupId&gt;org

import java.io.File; import java.io.IOException; If you're using Gradle

// Save the PDF document document.save(new File(fileName)); } }

/** * Generate a PDF document with a single page containing text. * * @param fileName the output PDF file name * @param text the text to be written in the PDF * @throws IOException if an I/O error occurs */ public void generatePdf(String fileName, String text) throws IOException { // Create a new PDF document try (PDDocument document = new PDDocument()) { // Create a new page PDPage page = new PDPage(); document.addPage(page);