title: Java iText HTML to PDF <pre> block formatting
body: <p>I'm using iText to convert HTML file structure to PDF. My HTML files contain code snippets in <code>&lt;pre&gt;</code> blocks, but iText doesn't leave them formatted as they are.</p>
  
  <p>Example of my <code>&lt;pre&gt;</code> block:</p>
  
  <pre><code>&lt;something&gt;
     &lt;somethingelse&gt;
        some content
     &lt;/somethingelse&gt;
  &lt;/something&gt;
  </code></pre>
  
  <p>This is what iText outputs to PDF:</p>
  
  <pre><code>&lt;something&gt;  &lt;somethingelse&gt; some content  &lt;/somethingelse&gt;  &lt;/something&gt;
  </code></pre>
  
  <p>Is there a way to configure iText to format this correctly?</p>
  
  <p>My iText code snippet:</p>
  
  <pre><code>FileOutputStream os = new FileOutputStream(...);
  Document doc = new Document(PageSize.A4);
  PdfWriter writer = PdfWriter.getInstance(doc, os);
  CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
  HtmlPipelineContext htmlContext = new HtmlPipelineContext();
  
  htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
  htmlContext.setImageProvider(new AbstractImageProvider() {
      public String getImageRootPath() {
          ...
      }
  });
  
  Pipeline&lt;?&gt; pipeline = new CssResolverPipeline(cssResolver,
                         new HtmlPipeline(htmlContext,
                         new PdfWriterPipeline(doc, writer)));
  XMLWorker worker = new XMLWorker(pipeline, true);
  XMLParser parser = new XMLParser(worker);
  
  doc.open();
  
  for (String inputFile : inputFiles) {
      parser.parse(new FileInputStream(inputFile), StandardCharsets.UTF_8);
  }
  
  doc.close();
  </code></pre>