2

So I have an html table I'd like to convert to an image and I found a pretty neat API to do exactly this. It's called html2canvas. I have been able to use it pretty easily using HTML pages in my desktop but as soon as I try to run the exact same script in an aspx page on sharepoint absolutely nothing happens. No message, no error, nothing. I do NOT have access to the server so I am really locked into a server side solution. Here is the code I used (which worked for local html files).

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>

<body>
<div id="pdfWrapper" class="pdfWrapper" style="background-color:yellow;border:1px solid black;">
    <h1 id="capNum" style="color:maroon;background-color:blue;">Test</h1>
    <h2 id="title">some info goes here</h2>
    <p id="description">Yadda yadda yadda. Yadda yadda yadda. Yadda yadda yadda. Yadda yadda yadda. Yadda yadda yadda. Yadda yadda yadda. Yadda yadda yadda.</p>
    <table>
        <tr style="background-color:red;"><td>a1</td><td>a2</td><td>a3</td></tr>
        <tr style="background-color:blue;"><td>b1</td><td>b2</td><td>b3</td></tr>
        <tr style="background-color:green;"><td>c1</td><td>c2</td><td>c3</td></tr>
    </table>
</div>
<a href="javascript:viewAsImage();">View As Image</a>
</body>

<script>
function viewAsImage()
{
    html2canvas($("#pdfWrapper"),
    {
        onrendered: function (canvas)
        {
            var myImage = canvas.toDataURL("image/png");
            var tWindow = window.open(""); 
            $(tWindow.document.body).html("<img id='Image' src=" + myImage + " style='width:100%;'></img>");
        }
    });
}
</script>
</html>

I've tried implementations where I don't open a new page in case Sharepoint was blocking popups or something.. I am not really familiar with asp so it could just be something very simple I'm overlooking. The reason I can't just use HTML is I am also using CSOM to populate some of the table fields from a Sharepoint list before I create the image.

PLEASE. Any help on this matter would be so appreciated.

0

It is a security issue. Does the html2canvas script has sufficient rights to create images on your sharepoint folder? The folder needs to have write permissions in order to create temporarily images.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.