title: Convert jsp to PDF using flying saucer
body: <p>I have a jsp file which I like to convert it to PDF using  flying saucer. Here is the jsp file:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8" isELIgnored="false"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ taglib prefix="display" uri="http://displaytag.sf.net/el" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  %&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;JSP Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form name="testDBForm" action="&lt;%=basePath%&gt;/TestDatabase" method="post" onsubmit="return true"&gt;
          &lt;input type="submit" id="btnInsert" value="btnInsert" name="btnInsert" text="INSERT"/&gt;
          &lt;input type="submit" id="btnSelect" value="btnSelect" name="btnSelect" text="SELECT"/&gt;
          &lt;input type="submit" id="btnDelete" value="btnDelete" name="btnDelete" text="DELETE"/&gt;
          &lt;input type="submit" id="btnUpdate" value="btnUpdate" name="btnUpdate" text="UPDATE"/&gt;
    &lt;/form&gt;
    &lt;c:if test="${not empty message}"&gt;
        &lt;h1&gt;${message}&lt;/h1&gt;
    &lt;/c:if&gt;
    &lt;c:if test="${not empty insert}"&gt;
        &lt;h1&gt;Insert: ${message}&lt;/h1&gt;
    &lt;/c:if&gt;
    &lt;c:if test="${not empty select}"&gt;
        &lt;h1&gt;Select: ${message}&lt;/h1&gt;
    &lt;/c:if&gt;
    &lt;c:if test="${not empty update}"&gt;
        &lt;h1&gt;Update: ${message}&lt;/h1&gt;
    &lt;/c:if&gt;
    &lt;c:if test="${not empty delete}"&gt;
        &lt;h1&gt;Delete: ${message}&lt;/h1&gt;
    &lt;/c:if&gt;
  
  &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>Here is the servlet code that I am using for parsing html to pdf:</p>
  
  <pre><code>protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
      response.setContentType("application/pdf");
      String inputFile = "D:\\03072014\\src\\main\\webapp\\includes\\testDatabase.jsp";
      String url="";
      try {
          url = new File(inputFile).toURI().toURL().toString();
      } catch (MalformedURLException ex) {
          Logger.getLogger(HtmlToPdfTaxCardConvertor.class.getName()).log(Level.SEVERE, null, ex);
      }
      OutputStream os=null;
      try {
          os = response.getOutputStream();
      } catch (IOException ex) {
          Logger.getLogger(HtmlToPdfTaxCardConvertor.class.getName()).log(Level.SEVERE, null, ex);
      }
  
      ITextRenderer renderer = new ITextRenderer();
      renderer.setDocument(url);
      renderer.layout();
      try {
          renderer.createPDF(os);
          os.close();
      } catch (DocumentException ex) {
          Logger.getLogger(HtmlToPdfTaxCardConvertor.class.getName()).log(Level.SEVERE, null, ex);
      }
       catch (IOException  ex) {
          Logger.getLogger(HtmlToPdfTaxCardConvertor.class.getName()).log(Level.SEVERE, null, ex);
      }     
  </code></pre>
  
  <p>}
  }</p>
  
  <p>I got exception that</p>
  
  <pre><code>javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: The markup in    the document preceding the root element must be well-formed.
  </code></pre>
  
  <p>Could somebody help me and is it possible to create pdf from this kind of html page</p>