title: Base64 String to Json String
body: <p>I currently need to send a <strong>PDF</strong> file through an API by converting it to a <strong>Base64</strong> string. I have tested my code and realize that it cannot accept the contents in my <code>pdfBase64String</code> variable.</p>
  <p>I tried printing the <code>pdfBase64String</code> and it does not show up anything. I tried decoding back to a pdf file and it works so the problem should lie in the String itself. Is there anyway i can solve this problem? i would still want to send it in string and the other party who receives it will decode it back to the pdf file.</p>
  <pre class="lang-java prettyprint-override"><code>ByteArrayOutputStream ba = loadPdf(fileName);
  String pdfBase64String = StringUtils.newStringUtf8(Base64.encodeBase64(ba.toByteArray()));
  System.out.println(pdfBase64String);     //Does not show anything
  
  ApprovalReport approvalReport = new ApprovalReport(Long.valueOf(crisisID), pdfBase64String);
  URI uri = restTemplate.postForLocation(CMO_SERVICE_URI + &quot;/approvalReport/&quot;, approvalReport, ApprovalReport.class);
  </code></pre>