Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //form
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using iTextSharp.pdf.Wygenerowane;
- namespace Formm
- {
- public partial class Form1 : Form
- {
- public string FirstName
- {
- get { return Imie.Text; }
- set { Imie.Text = value; }
- }
- public Form1()
- {
- InitializeComponent();
- }
- public void button1_Click(object sender, EventArgs e)
- {
- new Example1();
- MessageBox.Show(" Zapisany do PDF-a");
- }
- public void Imie_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
- //folder wygenerowane/example1
- using System;
- using System.IO;
- // Importing necessary Library to work with iTextSharp 5.4.4
- using iTextSharp.text;
- using iTextSharp.text.pdf;
- using Formm;
- namespace iTextSharp.pdf.Wygenerowane
- {
- /// <summary>
- /// Exmaple 1: Creation of a PDF Document in 6 steps
- /// </summary>
- public class Example1
- {
- private readonly Form1 form;
- public Example1()
- {
- string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
- try
- {
- // Step 1: Creating System.IO.FileStream object
- using (FileStream fs = new FileStream(appRootDir + "/PDFs/" + "Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
- // Step 2: Creating iTextSharp.text.Document object
- using (Document doc = new Document())
- // Step 3: Creating iTextSharp.text.pdf.PdfWriter object
- // It helps to write the Document to the Specified FileStream
- using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
- {
- // Step 4: Openning the Document
- doc.Open();
- // Step 5: Adding a paragraph
- // NOTE: When we want to insert text, then we've to do it through creating paragraph
- doc.Add(new Paragraph(form.FirstName));
- // Step 6: Closing the Document
- doc.Close();
- }
- }
- // Catching iTextSharp.text.DocumentException if any
- catch (DocumentException de)
- {
- throw de;
- }
- // Catching System.IO.IOException if any
- catch (IOException ioe)
- {
- throw ioe;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement