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: