Itext&html2canvas JS screenshot Draw export PDF

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.