Advertisement
Guest User

pdf

a guest
Aug 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. //form
  2.  
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using iTextSharp.pdf.Wygenerowane;
  14. namespace Formm
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public string FirstName
  19.         {
  20.             get { return Imie.Text; }
  21.             set { Imie.Text = value; }
  22.         }
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.  
  29.         public void button1_Click(object sender, EventArgs e)
  30.         {
  31.             new Example1();
  32.             MessageBox.Show(" Zapisany do PDF-a");
  33.         }
  34.         public void Imie_TextChanged(object sender, EventArgs e)
  35.         {
  36.  
  37.         }
  38.     }
  39. }
  40.  
  41. //folder wygenerowane/example1
  42.  
  43. using System;
  44. using System.IO;
  45. // Importing necessary Library to work with iTextSharp 5.4.4
  46. using iTextSharp.text;
  47. using iTextSharp.text.pdf;
  48. using Formm;
  49.  
  50. namespace iTextSharp.pdf.Wygenerowane
  51. {
  52.     /// <summary>
  53.     /// Exmaple 1: Creation of a PDF Document in 6 steps
  54.     /// </summary>
  55.     public class Example1
  56.     {
  57.         private readonly Form1 form;
  58.         public Example1()
  59.         {
  60.             string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
  61.             try
  62.             {
  63.                 // Step 1: Creating System.IO.FileStream object
  64.                 using (FileStream fs = new FileStream(appRootDir + "/PDFs/" + "Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
  65.                 // Step 2: Creating iTextSharp.text.Document object
  66.                 using (Document doc = new Document())
  67.                 // Step 3: Creating iTextSharp.text.pdf.PdfWriter object
  68.                 // It helps to write the Document to the Specified FileStream
  69.                 using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
  70.                 {
  71.                     // Step 4: Openning the Document
  72.                     doc.Open();
  73.                     // Step 5: Adding a paragraph
  74.                     // NOTE: When we want to insert text, then we've to do it through creating paragraph
  75.                     doc.Add(new Paragraph(form.FirstName));
  76.                     // Step 6: Closing the Document
  77.                     doc.Close();
  78.                 }
  79.             }
  80.             // Catching iTextSharp.text.DocumentException if any
  81.             catch (DocumentException de)
  82.             {
  83.                 throw de;
  84.             }
  85.             // Catching System.IO.IOException if any
  86.             catch (IOException ioe)
  87.             {
  88.                 throw ioe;
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement