[. Net]-use ITEXTSHARP to generate template-based PDFs, generate new files, and retain form fields

Source: Internet
Author: User

Background

Pre-populate the form items based on the PDF Template, generate a new PDF file, and keep the form fields allowed to continue modifying.

Code snippet

Using ITextSharp.text.pdf;/ * Code Snippet * /using (var dia = new SaveFileDialog ())) {dia.    Filter = @ "PDF files|*.pdf"; Dia. FileName = string.    Format ("pdf_{0}", DateTime.Today.ToString ("Yyyy-mm-dd")); if (DIA. ShowDialog () = = DialogResult.OK) {using (FileStream Fswrite = new FileStream (DIA.) FileName, FileMode.OpenOrCreate, FileAccess.Write)) {using (var reader = new Pdfreader (@ "\templates\pdf                Template\template01.pdf ")) {using (var stamper = new Pdfstamper (reader, Fswrite)) {Stamper. Writer.closestream = false;//Keep form fields, allow to continue editingStamper. Formflattening = false;//Update form field fieldsvar form = Stamper.                    Acrofields; Form.                    SetField ("form1[0]. #subform [0].flt_txtusername[0]", "username"); Stamper.                Close (); }}} MessageBox.Show ("Report had been exported", resources.common_successed, MESSAGEBOXBUTTONS.O    K, MessageBoxIcon.Information); }}

[. Net]-use ITEXTSHARP to generate template-based PDFs, generate new files, and retain form fields

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.