Use PDF template files in. NET Core to generate PDF files instead of Web Print controls!

Source: Internet
Author: User

These days to find the Web Print control, either charge, or free to use only in IE!

I just want to make a simple label paper! Baidu 2 days, see a man said can use PDF, and then started Baidu. Found an article

http://www.jianshu.com/p/d518d0988621 This article code all excerpt to this article, post only for record!

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

Begin

First use Word to make a template file, label printing note the margins, and then save as a PDF file

Two. Then download Adobe Acrobat Pro, select PDF form when creating, and set the corresponding key name

Then there's the code.

Public Fileresult Index () {//Gets the Chinese font, and the third parameter indicates whether to sneak into the font, but it is embedded as long as the encoded font. Basefont Basefont = Basefont.createfont (@ "c:\windows\fonts\simsun.ttc,1", Basefont.identity_h, BaseFont.NOT_            EMBEDDED);            Read template file Pdfreader reader = new Pdfreader (@ "C:\Users\kisme\OneDrive\pdfmoban.pdf");            Create a file stream to hold the fill template after the file System.IO.MemoryStream stream = new System.IO.MemoryStream ();            Pdfstamper stamp = new Pdfstamper (reader, stream); Set the form font, in the high version is useful, the high version added this sentence will not insert the font, the low version useless//stamp.            Acrofields.addsubstitutionfont (Basefont); Acrofields form = stamp.            Acrofields; Whether the form text box is locked stamp.            Formflattening = true;            dictionary<string, string> para = new dictionary<string, string> (); Para.            ADD ("username", "national section"); Para.            ADD ("Usertel", "133333333"); Para.            ADD ("Workservice", "computer does not turn on, may be a power problem, repair before the price (main engine missing side cover, there is important information, can not be re-installed)"); Para. ADD ("Maketime", "December 2017 11st 12:24 "); Para.            ADD ("Recvicename", "xxx"); Para.            ADD ("Workername", "xxx"); Para.            ADD ("Weixinpic", "");                Populate the form with a para (attribute-value) dictionary for the form foreach (keyvaluepair<string, string> parameter in para) {                To enter Chinese, set the font of the field; Form. SetFieldProperty (parameter.                Key, "Textfont", Basefont, NULL);                Set values for fields that need to be assigned values; Form. SetField (parameter. Key, parameter.            Value); }//Close IO stream stamp sequentially.            Close (); Reader.            Close (); Generate file Fileresult Fileresult = new Filecontentresult (stream.            ToArray (), "application/pdf");            Fileresult.filedownloadname = "4.pdf";        return fileresult; }

  

Then Baidu a jquery PDF print script, done!

Use PDF template files in. NET Core to generate PDF files instead of Web Print controls!

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.