html2canvas

html2canvas使用事项。

强颜欢笑 提交于 2019-12-05 01:10:01
在使用html2canvas时,执行转换时不得出现父辈元素(上级 、上上级)等,有display:none 属性,否则报错。 生成时如果出现提示图片跨域,在图片地址上加上 时间戳 ( new Date().getTime() ) 及属性 crossOrigin="anonymous" 来源: oschina 链接: https://my.oschina.net/u/3757195/blog/3137161

html2canvas使用事项。

人走茶凉 提交于 2019-12-05 01:09:47
在使用html2canvas时,执行转换时不得出现父辈元素(上级 、上上级)等,有display:none 属性,否则报错。 生成时如果出现提示图片跨域,在图片地址上加上 时间戳 ( new Date().getTime() ) 及属性 crossOrigin="anonymous" 来源: oschina 链接: https://my.oschina.net/u/3757195/blog/3137161

Looping html2canvas

谁说胖子不能爱 提交于 2019-12-05 00:24:03
问题 I'm having a bit of trouble trying to implement the html2canvas script in a for loop. I'm writing a Javascript function that uses an array of data to modify the style of a group of elements, captures the container div as a canvas, converts it into an image, appends it to the document body and then moves on to the next index of the array. The part where I'm having trouble is at the very end of my loop: html2canvas(document.getElementById("background"), { onrendered: function(canvas) { var

HTML2Canvas generating blank image in Ionic4 angular proj. No error in console. Same code generates proper image in plain html/javascript

♀尐吖头ヾ 提交于 2019-12-04 18:07:41
I have html2canvas installed and imported in home.page.ts in my Ionic4 angular test project. I have a plain 100px X 100px, yellow background div with a single line of text. I am passing this div to html2canvas to be downloaded as png. html2canvas is listing all steps (no errors) in the console and generating the png with the same size as the given div but the div is empty.It does not have the color of the div or the text. Changing the size of the div takes effect properly meaning the generated image has the same size as the div. This test project demonstrate the issue - https://stackblitz.com

html2canvas output selected div PHP

社会主义新天地 提交于 2019-12-04 16:51:39
this code almost works this will output the entire page into a jpg question : how can i grab only the content inside '#myDiv' and output that as a jpg file? JS: $('.myButton').click(function(){ $('#myDiv').html2canvas();//<< has no effect var queue = html2canvas.Parse(); var canvas = html2canvas.Renderer(queue,{elements:{length:0}}); var img = canvas.toDataURL(); img.replace(/^data:image\/(png|jpg);base64,/, ""); $.post( "postIO.php", {img:img}, function(data) { //$('#recieve').append(data); }); return false; }); postIO.php: $canvasImg = $_POST['img']; //$canvasImg = str_replace('data:image

How to take a screenshot in PDF using JavaScript

梦想的初衷 提交于 2019-12-04 15:24:11
I'm using Html2Canvas for capture the screenshot of my screen i want to get a output as a PDF file now i'm getting output in png image how to convert or get output in pdf function genScreenshot() { html2canvas(document.body, { onrendered: function(canvas) { $('#box1').html(""); $('#box1').append(canvas); if (navigator.userAgent.indexOf("MSIE ") > 0 || navigator.userAgent.match(/Trident.*rv\:11\./)) { var blob = canvas.msToBlob(); window.navigator.msSaveBlob(blob,'Test file.png'); } else { $('#test').attr('href', canvas.toDataURL("image/png")); $('#test').attr('download','Test file.png'); $('

html2canvas以及domtoimage的使用踩坑总结

有些话、适合烂在心里 提交于 2019-12-04 14:26:59
前言 首先做个自我介绍,我是成都某企业的一名刚刚入行约一年的前端,在之前的开发过程中,遇到了问题,也解决了问题,但是在下一次解决相同问题的时候,只对这个问题有一丝丝的印象,还需要从新去查找,于是,我注册了segmemtfault,便于搜集我的问题总结,以及将踩坑经验分享给每一个开发人员,好了,闲话不多说。 需求 需求:要求能够实现根据后端返回的数据生成一张image,便于用户将图片分享到朋友或者朋友圈,取得用户的关注。 开始踩坑 一.html2canvas对于跨域图片,转换的时候会将跨域图片识别为空白。 问题分析: 既然是由于跨域引起的问题,那我们让资源不跨域不就可以访问了吗? 解决办法: 将图片放置服务器,通过nginx进行代理资源,前端访问图片便不涉及到跨域问题。 二.html2canvas动态加载内容,通过canvas转换出来的数据,图片为空 问题分析: 内容是动态加载进来的,转换肯定是在请求完毕之后再去转换,但是在请求完毕之后去转换,按理说所需要的所有数据都已经到达前端,应该可以转换,经过思考,发现图片内容从后台读取需要一定时间去解析,才能够完整的将图片资源展示出来,html2canvas是将页面上显示的dom元素,经过解析将dom画在canvas上在转换为image图片格式。 解决办法: 1.让html2canvas转换代码等待一定时间,在进行转换操作,可进行转换

How to save html2canvas image into System Folder in jquery

送分小仙女□ 提交于 2019-12-04 11:05:15
I have a form with id="form1" inside this form i have a graph.Now i am using html2canvas to get the image of this form1.Here is my code.. <script type="text/javascript"> $(document).ready(function () { $('#add_button').click(function () { alert("hiii"); $('form1').html2canvas(); var queue = html2canvas.Parse(); var canvas = html2canvas.Renderer(queue, { elements: { length: 1} }); var img = canvas.toDataURL(); window.open(img); alert("Hello"); }); }); </script> <form id="form1" runat="server"> <div style="padding-left:150px"> <asp:Literal ID="FCLiteral1" runat="server"></asp:Literal> </div>

html2canvas在vue下的巨坑

纵然是瞬间 提交于 2019-12-04 08:02:01
公司有个需求就是要在前端生成图片首先想到的是用canvas生成图片,自己画这也太耗时间了吧!后面在npm上一查有个html2canvas的框架可以用这里附上地址 html2canvas 使用起来也特别简单,官网是这么描述的 html <div id="capture" style="padding: 10px; background: #f5da55"> <h4 style="color: #000; ">Hello world!</h4> </div> js html2canvas(document.querySelector("#capture")).then(canvas => { document.body.appendChild(canvas) }); html2canvas(document.querySelector("#capture") { async: true }).then(canvas => { document.body.appendChild(canvas) }); 如果你要配置一些参数可以在传入dom的后面进行 object 传参 官网文档可查 官网文档 我自己的工程环境是vue-cli会进行webpack打包在ios下运行的时候会出现错误因为我要生成一张图片是的canvas api 是 toDataURL 这错误在ios一直显示是权限问题 在ios

Download PDF is not rendering the complete list of data from ngFor using html2canvas

血红的双手。 提交于 2019-12-04 06:32:34
问题 I have the below code to download the elements in ngFor as a PDF . My html is a array list of data information rendered using ngFor . I have a downloadPDF function written which accepts the id as a parameter and loops through the array list and has to save entire loop of array data as PDF when I click on the downloadPDF button. I am not sure why its saving only the first element from the array finalArList . I have attached the JSON response of finalArList and also the pdf file for reference.