Save the Html code as a PDF file,

Source: Internet
Author: User

Save the Html code as a PDF file,

Some time ago, Insus. NET has implemented the http://www.cnblogs.com/insus/p/4313092.html of "Upload Text Document and convert to PDF" and "Save a section of captured View as part of View (Partial View. Currently, Insus. NET wants to combine the above two articles to implement another function, that is, to save the intercepted Html as a PDF file.

In the previous article, converting Text to pdf directly converts the file. Now we do not need to save the html code as a file before conversion. Use the iTextSharp component to Convert pdf files, which can also be converted from strings. So we don't have to go around.


In the controller, write a conversion pdf operation. The following two codes convert the string to byte. The obtained byte just matches the transfer parameter type of iTextSharp.

Byte [] bytes = new byte [str. length * sizeof (char)]; System. buffer. blockCopy (str. toCharArray (), 0, bytes, 0, bytes. length); View Code


Complete code example:

 

In the view, I add a button to modify the url path:


Demo:


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.