Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using iTextSharp.pdf.Wygenerowane;
  11. namespace Formm
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public string FirstName
  16.         {
  17.             get { return Imie.Text; }
  18.             set { Imie.Text = value; }
  19.         }
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         public void button1_Click(object sender, EventArgs e)
  27.         {
  28.             new Example1(this);
  29.             MessageBox.Show(" Zapisany do PDF-a");
  30.         }
  31.         public void Imie_TextChanged(object sender, EventArgs e)
  32.         {
  33.  
  34.         }
  35.     }
  36. }
  37.  
  38.  
  39. using System;
  40. using System.IO;
  41. using iTextSharp.text;
  42. using iTextSharp.text.pdf;
  43. using Formm;
  44. namespace iTextSharp.pdf.Wygenerowane
  45. {
  46.     public class Example1
  47.     {
  48.         private readonly Form1 form;
  49.         public Example1(Form1 form)
  50.         {
  51.             string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
  52.             try
  53.             {
  54.                 this.form = form;
  55.                 using (FileStream fs = new FileStream(appRootDir + "/PDFs/" + "Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
  56.                 using (Document doc = new Document())
  57.                 using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
  58.                 {
  59.                     doc.Open();
  60.                     doc.Add(new Paragraph("chuj"+Convert.ToString(form.FirstName)));
  61.                     doc.Close();
  62.                 }
  63.             }
  64.             // Catching iTextSharp.text.DocumentException if any
  65.             catch (DocumentException de)
  66.             {
  67.                 throw de;
  68.             }
  69.             // Catching System.IO.IOException if any
  70.             catch (IOException ioe)
  71.             {
  72.                 throw ioe;
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement