Upload Text Document and convert it to PDF. Upload text Document pdf

Source: Internet
Author: User

Upload Text Document and convert it to PDF. Upload text Document pdf

Today, I learned some PDF-related knowledge in the ASP. NET MVC environment. The idea is to convert a file into a PDF file when the file is uploaded successfully.

Open your project, run the NuGet Package Manager, and download an item named iTextSharp:



Click "Install". The system prompts you to confirm the installation. If the installation is successful or the project has been installed, the status is shown as follows:

 
Create an Action on the controller ):

 

In the controller, another operation method is to process file upload and Convert PDF:


FileStream class to open the file and read, get the byte [] array of the document. ITextSharp Class Object mongowriter, go to the GetInstance instance, and finally pass the array byte [] of the document to the paragrahp () method of the iTextSharp object.

After the operation is created based on the controller, we can create the view UploadConvertPDF (). This exercise uses Razor to upload files:

 
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.