title: How to convert HTML to PDF using iText
body: <pre><code>import java.io.File;
  import java.io.FileOutputStream;
  import java.io.OutputStream;
  import com.itextpdf.text.Document;
  import com.itextpdf.text.Paragraph;
  import com.itextpdf.text.pdf.PdfWriter;
  
  public class GeneratePDF {
      public static void main(String[] args) {
          try {
  
              String k = "&lt;html&gt;&lt;body&gt; This is my Project &lt;/body&gt;&lt;/html&gt;";
  
              OutputStream file = new FileOutputStream(new File("E:\\Test.pdf"));
  
              Document document = new Document();
              PdfWriter.getInstance(document, file);
  
              document.open();
  
              document.add(new Paragraph(k));
  
              document.close();
              file.close();
  
          } catch (Exception e) {
  
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>This is my code to convert HTML to PDF. I am able to convert it but in PDF file it saves as whole HTML while I need to display only text. <code>&lt;html&gt;&lt;body&gt; This is my Project &lt;/body&gt;&lt;/html&gt;</code> gets saved to PDF while it should save only <code>This is my Project</code>.</p>