title: IllegalPdfSyntaxException: Unbalanced save/restore state operators
body: <p>I am working on <code>iText</code> converting HTML with CSS to PDF.</p>
  
  <p>In my CSS, I have:</p>
  
  <pre><code>    background: linear-gradient(to bottom, #fff 0%, #e6e6e6 100%);
  </code></pre>
  
  <p>With this, it is throwing below exception:</p>
  
  <pre><code>IllegalPdfSyntaxException: Unbalanced save/restore state operators
  (exception at document.close();)
  </code></pre>
  
  <p>Here's the code I have written:</p>
  
  <pre><code>Document document = null;
  try{
   FileOutputStream fileOuputStream = new FileOutputStream("D:\\DEV\\testpdf.html"); 
   fileOuputStream.write(str.getBytes());
   String CSS = "D:\\DEV\\all.css";
   CSSResolver cssResolver = new StyleAttrCSSResolver();
  
   CssFile cssFile = XMLWorkerHelper.getCSS(new FileInputStream(CSS));
   cssResolver.addCss(cssFile);
   FileInputStream fileInputStream = new FileInputStream("D:\\DEV\\testpdf.html");
      // step 1
     document = new Document();
      // step 2
     PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));
      // step 3
      document.open();
      XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
      CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
      HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
      htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
      PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
      HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
      CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
      // XML Worker
      XMLWorker worker = new XMLWorker(css, true);
      XMLParser p = new XMLParser(worker);
      p.parse(fileInputStream);
      // step 4
    //  XMLWorkerHelper.getInstance().parseXHtml(writer, document, fileInputStream);
      //step 5
  
       fileInputStream.close();
       fileOuputStream.close();
      System.out.println( "PDF Created!" );
  
  
  }catch(IOException e){
      e.printStackTrace();
      return false;
  }
   document.close();
  </code></pre>
  
  <p>If I remove this from my CSS:</p>
  
  <pre><code>background: linear-gradient(to bottom, #fff 0%, #e6e6e6 100%);
  </code></pre>
  
  <p>Then, I am able to generate PDF with out above exception.</p>
  
  <p>iText version:</p>
  
  <pre><code>        &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;itextpdf&lt;/artifactId&gt;
          &lt;version&gt;5.4.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf.tool&lt;/groupId&gt;
          &lt;artifactId&gt;xmlworker&lt;/artifactId&gt;
          &lt;version&gt;5.4.1&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>