Home >Web Front-end >HTML Tutorial >Html code saved as Pdf file_html/css_WEB-ITnose

Html code saved as Pdf file_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:48:361128browse

Some time ago, Insus.NET implemented "Upload a Text document and convert it to PDF" and "Capture a section of the view and save it as a partial view (Partial View)". Now Insus.NET wants to combine the above two articles to implement another function, which is to save the intercepted Html as a pdf file.

The previous article to convert a Text document to PDF is to convert the file directly. Now we don't have to save the html code as a file and convert it later. Use the iTextSharp component to convert pdf, which can also be converted from strings. So we don't have to go full circle.


In the controller, write an operation to convert pdf. There are two codes below to convert strings into bytes. The obtained bytes just match the input parameter type of iTextSharp.

 byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);


Full code example:

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


Demo:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn