Advertisement
Pavle_nis

Untitled

Feb 7th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 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.  
  11. using System.IO;
  12. using iTextSharp.text;
  13. using iTextSharp.text.pdf;
  14. using Spire.Doc;
  15.  
  16. namespace WindowsFormsApp7
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void Form1_Load(object sender, EventArgs e)
  26.         {
  27.            
  28.         }
  29.  
  30.         private void btnSave_Click(object sender, EventArgs e)
  31.         {
  32.             SaveFileDialog dlg = new SaveFileDialog();
  33.             dlg.Filter = "PDF Documents|*.pdf|Word Documents|*.docx|Text Documents|*.txt";
  34.  
  35.             string fileName = string.Empty;
  36.  
  37.             if (dlg.ShowDialog() == DialogResult.OK)
  38.             {
  39.                 fileName = dlg.FileName;
  40.  
  41.                 switch (dlg.FilterIndex)
  42.                 {
  43.                     case 1:
  44.                         iTextSharp.text.Document document = new iTextSharp.text.Document();
  45.                         PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
  46.                         document.Open();
  47.  
  48.                         Paragraph p1 = new Paragraph(richTextBox1.Text);
  49.                         document.Add(p1);
  50.                         document.Close();
  51.                         break;
  52.  
  53.                     case 2:
  54.                         Spire.Doc.Document doc = new Spire.Doc.Document();
  55.                         Spire.Doc.Section section = doc.AddSection();
  56.  
  57.                         Spire.Doc.Documents.Paragraph paragraph = section.AddParagraph();
  58.                         paragraph.AppendText(richTextBox1.Text);
  59.  
  60.                         doc.SaveToFile(fileName, FileFormat.Docx);
  61.                         break;
  62.  
  63.                     case 3:
  64.                         File.WriteAllText(fileName, richTextBox1.Text);
  65.                         break;
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement