locked
Displaying images and PDF’s stored as Annotations in a HTML Web Resource RRS feed

  • Question

  • Displaying Annotation images in a HTML Web Resource works fine. The image is displayed no problem.

    However, I cannot display a PDF and/or Visio file.

    The code in bold is what isn’t working, I think.

    What am I doing wrong?

    <html>
    <head>
        <title>Annotation Viewer</title>
            <script type="text/javascript" src="jquery"></script> 
            <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
            <script type="text/javascript">
                function getImages(guid) {
                    var context = GetGlobalContext();
                    $.getJSON(context.getServerUrl() + "/XrmServices/2011/OrganizationData.svc/AnnotationSet?$select=AnnotationId,DocumentBody,MimeType&$filter=AnnotationId eq guid'" + guid + "'", function (data) {
                        if (data.d.results.length > 0) {
                            var singleRecord = data.d.results[0]
                            loadImage(singleRecord);
                        }
                    });
                }
    
    
                function loadImage(record) {
                    while (attachment_content_table.rows.length > 0) {
                        attachment_content_table.deleteRow(0);
                    }
                    var newRow = attachment_content_table.insertRow(0);
                    var newCell = newRow.insertCell(0);
    
                    if (record.MimeType == "image/png" || record.MimeType == "image/gif" || record.MimeType == "image/jpeg") {
                        newCell.innerHTML = "<img src='data:" + record.MimeType + ";base64," + record.DocumentBody + "'/>";
                    }
                    else if (record.MimeType == "application/pdf" || record.MimeType == "application/vnd.visio") {
                        newCell.innerHTML = "<object data='data:" + record.MimeType + ";base64," + record.DocumentBody + "' type='" + record.MimeType + "'><embed src='data:" + record.MimeType + ";base64," + record.DocumentBody + "' type='" + record.MimeType + "' /></object>";
                    }
                }
        </script>
    </head>
    <body>
        <table id="attachment_content_table" />
    </body>
    </html>




    • Edited by AllCam Sunday, November 17, 2013 8:31 PM
    Sunday, November 17, 2013 8:13 PM