text convert to pdf
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
public class TextToPdfConverter {
public static void main(String[] args) {
String text = "This is the text content to be converted to PDF.";
// Specify the output file path
String outputPath = "output.pdf";
convertTextToPdf(text, outputPath);
}
public static void convertTextToPdf(String text, String outputPath) {
try {
// Create a new PDF document
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(outputPath));
// Open the document
document.open();
// Add the text to the document
document.add(new Paragraph(text));
// Close the document
document.close();
System.out.println("PDF created successfully!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
0 Comments
Post a Comment