How to Write PDF using Java
java
Solution
Your code is writing a plain text file with the extension `.pdf`. A PDF file is not a plain text file.
There are several libraries available for working with PDF files in Java, for example iText and Apache PDFBox.
Problem
I need to write some text in to a PDF document using Java. I wrote a code for that. But i'm unable to open the file. If you guys have some idea please share with me. ``` public class WritPDF { public static void main(String[] args) { Writer writer = null; try { String text = "This is a text file"; File file = new File("C:/Users/PrinterTest/Hi1.pdf"); writer = new BufferedWriter(new FileWriter(file));; writer.write(text); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) { } } catch (IOException e) {} } } } ```