title: How to Decode base64 image encoded by window.btoa using Java
body: <p>I have an svg image which I want to export as png.  </p>
  
  <p>In client side using javascript, I am converting it into base64</p>
  
  <pre><code>var s = new XMLSerializer().serializeToString(document.getElementById("svg"))
  var encodedData = window.btoa(s);
  </code></pre>
  
  <p>In server side I want to decode it and create a .png file</p>
  
  <pre><code>BASE64Decoder decoder = new BASE64Decoder();
  byte[] imageByte = decoder.decodeBuffer(string);
  </code></pre>
  
  <p>But this gives me a file which can't be opened.</p>
  
  <p>Or is there any other way I can export the svg as png. I can't use toDataUrl since my svg contains images from external source</p>