title: com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced begin/end text operators
body: <p>Struggling with this problem in iText with PdfContentByte. When I try to create new page I'm using below code-</p>
  
  <pre><code>           canvas = writer.getDirectContent();
             canvas.saveState();
  
  
             canvas.stroke();
             canvas.restoreState();
           ...
              canvas.endText();
              itextDocument.newPage();
  
              setUpperFontAndSize(canvas);
              canvas.beginText();
  </code></pre>
  
  <p>The issue is occurring at the time of calling endText(). Is there any solution for it??</p>