<img> inside div does not appear when used canvas2image

Asked

Viewed 74 times

0

I’m using a script to save a div in png. Inside this div has one , but this image does not appear in the final result, after saving. The code I’m using is this

$(function() { 
$("#btnSave").click(function() { 
    html2canvas($(".container-assinatura"), {
        onrendered: function(canvas) {
            theCanvas = canvas;
            document.body.appendChild(canvas);
            var photo = canvas.toDataURL('image/png');

            //Convert and download as image 
            Canvas2Image.saveAsPNG(canvas);
            // Clean up 
            document.body.removeChild(canvas);

         }

      });
   });
}); 

Remembering that this script doesn’t work in Chrome, only in Mozilla,and here in the company where I work,95% of people use Chrome. Edit: The HTML of my code is this

<div style="color:#000" class="container-assinatura">
                <div id="gerador">
                        <p style="margin-bottom: 0in"></p>
                        <table class="MsoNormalTable" style="border-collapse:collapse" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                                <tr style="height:84.8pt">
                                  <td style="width:154.25pt;border:none;border-right:solid #E36C0A 2.0pt; padding:0cm 5.4pt 0cm 5.4pt;height:84.8pt" valign="top" width="206">
                                        <p class="MsoNormal">
                                            <span style="font-size:16.0pt"><o:p>&nbsp;</o:p></span>
                                        </p>
                                        <p class="MsoNormal">
                                            <div id="logo_position">
                                                <img id="logo_filial" src="png/marca_laranja.png">
                                                <span
                                                style="font-size:9.0pt"><o:p></o:p>
                                                </span>

                                            </div>
                                        </p>
                                  </td>
                                  <td style="width:205.55pt;border:none;padding:0cm 5.4pt 0cm 5.4pt; height:84.8pt" valign="top" width="274">
                                    <p class="MsoNormal">
                                        <b>
                                            <span style="color:#E36C0A"><b>{{nome}}</b></span>                                      
                                        </b>

                                        <b>
                                            <span style="font-size:9.0pt;color:red"></span><br>
                                        </b>

                                        <b>
                                            <span style="font-size:9.0pt;color:gray">{{setor}}<i><br></i></span>
                                        </b>

                                        <span style="font-size:9.0pt;color:gray"><o:p></o:p></span>
                                    </p>
                                    <p class="MsoNormal">
                                        <span style="font-size:9.0pt;color:black"><b>Tel:</b> {{telefone}}<br><b>E-mail:</b> </span>
                                        <span style="font-size:9.0pt">
                                            <a href="mailto:{{email}}">
                                                <span style="color:blue">{{email}}</span>
                                            </a>
                                            <br><span><b>Rocket.Chat:</b> {{rocket}}</span>
                                            <span style="font-size:9.0pt"><o:p></o:p></span>
                                        </span>
                                    </p>
                                  </td>
                                </tr>
                              </tbody>
                            </table>
                        <p style="margin-bottom: -72px"><o:p>&nbsp;</o:p><font face="Ubuntu
                            Light"><font size="3"><br>
                            </font></font><br>
                        </p>
                        <div class="moz-signature"> </div>
                        <p style="margin-bottom: 0in"><br>
                        </p>
                        <div class="moz-signature"> </div>
                </div>           
            </div>
<input type="button" id="btnSave" class="btn btn-dark" value="Salvar Assinatura">

  • Strange, because I use and works in Chrome. Only with this code is difficult to help, post also your html

  • I edited with the <div code>

  • A doubt, on your screen, the image is displayed (without giving the scroll)?

  • What do you mean give the scrool? You talk scroll the screen down?

  • Exactly!!!!!

  • Yes, it usually appears on both of the monitors I use, one of which is slightly smaller than the main one.

  • You could reproduce the error in a JSFiddle?

  • The whole page itself is quite small, as the <div> is an email signature. The whole project is from a signature generator, so it’s nothing too extensive.

  • So please play this page on JSFiddle and then we can see the supposed mistake happening and help solve the problem.

  • I’ll try to use Jsfiddle.

  • https://jsfiddle.net/FxHound/04t28hau/

  • The problem is basically the following, when pressing the Save Signature button, that white <div> is saved in . png, but the logo (in this case the AMD logo) does not come in the final result in . png.

  • I don’t know if it has anything to do with it,..

Show 8 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.