Use the PDF template file in. net Core to generate a PDF file, instead of the WEB Print control !, Pdf Control

Source: Internet
Author: User

Use the PDF template file in. net Core to generate a PDF file, instead of the WEB Print control !, Pdf Control

In the past few days, WEB printing controls are either charged or free and can only be used in IE!

I just want to make a simple tag paper! Baidu 2 days, saw a man said he could use PDF, and then began Baidu .. found an article

Http://www.jianshu.com/p/d518d0988621 this article code all excerpted to this article, published only for record!

The difference is that the library I imported is iTextSharp. LGPLv2.Core. Fix.

Start

I. Use word to create a template file. If tags are printed, pay attention to the margin and save it as a PDF file.

2. Download adobe acrobat pro, select a pdf form during creation, and set the corresponding key name.

 

Then the code

Public FileResult Index () {// obtain the Chinese font. The third parameter indicates whether the font is embedded. BaseFont baseFont = BaseFont. createFont (@ "C: \ Windows \ Fonts \ simsun. ttc, 1 ", BaseFont. IDENTITY_H, BaseFont. NOT_EMBEDDED); // read the template file PdfReader reader = new PdfReader (@ "C: \ Users \ kisme \ OneDrive \ pdfmoban.pdf "); // create a file stream to save the file System after the filling template. IO. memoryStream stream = new System. IO. memoryStream (); PdfStamper stamp = new PdfStamper (reader, stream); // set the form font, which is useful in high versions. If this sentence is added to a higher version, the font will not be inserted, the earlier version is useless // stamp. specified fields. addSubstitutionFont (baseFont); required fields form = stamp. acroFields; // whether the stamp is locked in the form text box. formFlattening = true; Dictionary <string, string> para = new Dictionary <string, string> (); para. add ("username", "Guo ke"); para. add ("usertel", "133333333"); para. add ("workservice", "the computer cannot be turned on, it may be a power supply problem, pre-Repair Quotation (the host is missing side cover, there are important information, can not be reinstalled)"); para. add ("maketime", "December 11, 2017"); para. add ("recvicename", "XX"); para. add ("workername", "XX"); para. add ("weixinpic", ""); // fill the form. para is a (Attribute-value) Dictionary of the form, foreach (KeyValuePair <string, string> parameter in para) {// set the font of the domain to enter Chinese characters; form. setFieldProperty (parameter. key, "textfont", baseFont, null); // set the value for the field to be assigned; form. setField (parameter. key, parameter. value);} // close the io stream stamp in sequence. close (); reader. close (); // generate the file FileResult fileResult = new FileContentResult (stream. toArray (), "application/pdf"); // fileResult. fileDownloadName = "4.20."; return fileResult ;}

  

 

Then Baidu has a Jquery PDF script!

 

Related Article

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.