title: Attach PDF to Notes in Dynamic CRM using javascript
body: <p>I have PDF URL which i need to attach to my Notes area using javascript. I have tried below code but it didn't work. It says that PDF is corrupt while opening the PDF. Notes is getting created but when I click on PDF attachment. It throw an error of corrupt file while opening it.</p>
  
  <pre><code>    function CreateNotes()
      {
      var Annotation = new Object();
      Annotation.ObjectId = { LogicalName: "quote", Id: RecordId, Name: "" };
      Annotation.Subject = "Quote Report";
      Annotation.NoteText = "Downloaded Today";
      Annotation.FileName = "Quote.pdf";
  
      var PDFContentBase64 = btoa(unescape(encodeURIComponent(PDFURL)));
      Annotation.DocumentBody = PDFContentBase64;
      Annotation.MimeType = "application/pdf";
  
  
       createRecordSync(Annotation,"AnnotationSet");
       }
  
       function createRecordSync(entityObject, odataSetName) {
       var jsonEntity = window.JSON.stringify(entityObject);
       var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
       var createRecordReq = new XMLHttpRequest();
       var ODataPath = getServerUrl() + ODATA_ENDPOINT;
       createRecordReq.open("POST", ODataPath + "/" + odataSetName, false);
       createRecordReq.setRequestHeader("Accept", "application/json");
      createRecordReq.setRequestHeader("Content-Type", "application/json;   charset=utf-8");
      createRecordReq.send(jsonEntity);
      var newRecord = JSON.parse(createRecordReq.responseText).d;
      return newRecord;
      }
      function getServerUrl() {
          return Xrm.Page.context.getClientUrl()
       }
  </code></pre>