Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 System.IO;
- using iTextSharp.text;
- using iTextSharp.text.pdf;
- using Spire.Doc;
- namespace WindowsFormsApp7
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- SaveFileDialog dlg = new SaveFileDialog();
- dlg.Filter = "PDF Documents|*.pdf|Word Documents|*.docx|Text Documents|*.txt";
- string fileName = string.Empty;
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- fileName = dlg.FileName;
- switch (dlg.FilterIndex)
- {
- case 1:
- iTextSharp.text.Document document = new iTextSharp.text.Document();
- PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
- document.Open();
- Paragraph p1 = new Paragraph(richTextBox1.Text);
- document.Add(p1);
- document.Close();
- break;
- case 2:
- Spire.Doc.Document doc = new Spire.Doc.Document();
- Spire.Doc.Section section = doc.AddSection();
- Spire.Doc.Documents.Paragraph paragraph = section.AddParagraph();
- paragraph.AppendText(richTextBox1.Text);
- doc.SaveToFile(fileName, FileFormat.Docx);
- break;
- case 3:
- File.WriteAllText(fileName, richTextBox1.Text);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement