title: Creating PDF file from HTML causes text to exceed the right margin (java + itext)
body: <p>I'm using a rich text editor on the frontend to let users create PDF files (using java + itext). The problem is that when a user enters a large amount of spaces (pressing the space bar), it causes the text to exceed the right margin of the PDF file.</p>
  
  <p>Normal text:
  <a href="https://i.stack.imgur.com/2J2tP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2J2tP.png" alt="enter image description here"></a></p>
  
  <p>PDF:
  <a href="https://i.stack.imgur.com/71mwa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/71mwa.png" alt="enter image description here"></a></p>
  
  <p>Now I add a lot of whitespaces:
  <a href="https://i.stack.imgur.com/Ds83p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ds83p.png" alt="enter image description here"></a></p>
  
  <p>PDF:
  <a href="https://i.stack.imgur.com/BRDyF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BRDyF.png" alt="enter image description here"></a></p>
  
  <p>This is the HTML template I'm using to generate the PDF:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;
      &lt;style&gt;@page { size: A4; margin: 15mm 15mm 30mm 15mm; @bottom-left { font-family: Verdana; font-size: 10.0pt; content: "P&amp;aacute;gina " counter(page) " de " counter(pages); } } body { font-family: Verdana; font-size: 10.0pt; } table { border-collapse: collapse; border-spacing: 0; table-layout: auto; -fs-table-paginate: paginate;}
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;table style="width: 100%;"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th style="width: 100%;"&gt;
                      some header
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tfoot&gt;
              &lt;tr&gt;
                  &lt;td style="width: 100%;"&gt;
                      some footer
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tfoot&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      text from rich editor goes here
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I already tried setting the table and the body to a specific width in pixels, but it generates the PDF with the same problem.</p>
  
  <p>Here's the code that generates the PDF:</p>
  
  <pre><code>private void createPdfFile(Documento documento, String pathPdf) throws DocumentException, IOException {
      PdfWriter pdfWriter = new PdfWriter(new FileOutputStream(pathPdf));
      PdfDocument pdfDocument = new PdfDocument(pdfWriter);
  
      PdfDocumentInfo pdfInfo = pdfDocument.getDocumentInfo();
      pdfInfo.setCreator(creatorText);
  
      if (!StringUtils.isEmpty(documento.getTitleMetadata())) {
          pdfInfo.setTitle(documento.getTitleMetadata());
      }
      if (!StringUtils.isEmpty(documento.getAuthorMetadata())) {
          pdfInfo.setAuthor(documento.getAuthorMetadata());
      }
      if (!StringUtils.isEmpty(documento.getSubjectMetadata())) {
          pdfInfo.setSubject(documento.getSubjectMetadata());
      }
  
      ConverterProperties converterProperties = new ConverterProperties();
      HtmlConverter.convertToPdf(htmlHeader + documento.getBodyHtml() + htmlFooter, pdfDocument, converterProperties);
  
      pdfDocument.close();
  }
  </code></pre>