Html2canvas JS
Html
1 < Div ID = "Divpdf" > 2 Required Area 3 </ Div >
Js
1<script src= ". /js/html2canvas.js "></script>2<script type= "Text/javascript" >3 4 functiongetpdf () {5Html2canvas ($ (' #divPDF '),6 {7Onrendered:function(canvas) {8 varImgurl =Canvas.todataurl ();//acquired BASE64 encoding9 }Ten }); One } A -</script>
Background using picture Base64 encoding for image conversion
1 //<summary>2 ///convert Base64 encoding to image3 /// </summary>4 /// <param name= "base64string" >Base64 String</param>5 /// <returns>The conversion succeeded in returning the image; Failed returns null</returns>6 Public stringBase64toimage (stringImgname,stringBase64string,stringpath)7 {8base64string = Base64string.replace ("Data:image/png;base64,","");9MemoryStream ms =NULL;TenSystem.Drawing.Image Image =NULL; One stringImgurl = path +"\\"+ Imgname +". PNG"; A byte[] Imagebytes =convert.frombase64string (base64string); -ms =NewMemoryStream (Imagebytes,0, imagebytes.length); -Ms. Write (Imagebytes,0, imagebytes.length); theImage = System.Drawing.Image.FromStream (MS,true); - image. Save (Imgurl); - returnImgurl; -}
Add a watermark to a PDF file IText WaterMark
1 Public voidAddwatermark (stringFilelocation,stringPathintXinty)2 {3 stringwatermarklocation = path +"\\watermark.png";4Document document =NewDocument ();5Pdfreader Pdfreader =NewPdfreader (filelocation);6Pdfstamper stamp =NewPdfstamper (Pdfreader,NewFileStream (Filelocation.replace (". pdf","[Temp][file].pdf") , FileMode.Create));7 8ITextSharp.text.Image img =iTextSharp.text.Image.GetInstance (watermarklocation);9Img. SetAbsolutePosition (x, y);//set the position in the document where you want the watermark to appear (0,0 = bottom left corner of the page)Ten pdfcontentbyte WaterMark; One for(intpage =1; Page <= pdfreader.numberofpages; page++) A { -WaterMark =stamp. Getovercontent (page); - watermark.addimage (IMG); the } -Stamp. Formflattening =true; - stamp. Close (); - pdfreader.close (); + //Now Delete the original file and rename the temp file to the original file - File.delete (filelocation); +File.move (Filelocation.replace (". pdf","[Temp][file].pdf"), filelocation); A at}
Itext&html2canvas JS Drawing export PDF