code: public void sanityCheck() {
      	if (mcDepth != 0) {
      		throw new IllegalPdfSyntaxException("Unbalanced marked content operators." );
      	}
      	if (inText) {
      		throw new IllegalPdfSyntaxException("Unbalanced begin/end text operators." );
      	}
      	if (layerDepth != null && !layerDepth.isEmpty()) {
      		throw new IllegalPdfSyntaxException("Unbalanced layer operators." );
      	}
      	if (!stateList.isEmpty()) {
      		throw new IllegalPdfSyntaxException("Unbalanced save/restore state operators." );
      	}
      }
docs: Checks for any dangling state: Mismatched save/restore state, begin/end text,
  begin/end layer, or begin/end marked content sequence.
  If found, this function will throw.  This function is called automatically
  during a reset() (from Document.newPage() for example), and before writing
  itself out in toPdf().
  One possible cause: not calling myPdfGraphics2D.dispose() will leave dangling
  saveState() calls.
  @since 2.1.6
  @throws IllegalPdfSyntaxException (a runtime exception)