예제 #1
0
        private void openFile(string fileName)
        {
            string[] fileSplit = fileName.Split('.');

            if (fileSplit[fileSplit.Length - 1] == "docx")
            {
                DocxToText dtt = new DocxToText(fileName);
                richTextBoxEditor.Text = dtt.ExtractText();
            }
            else if (fileSplit[fileSplit.Length - 1] == "doc")
            {
                MessageBox.Show("Tyvärr stödjer inte programmet det gamla wordformatet (.doc). Prova med att spara om det till det nya formatet (.docx), eller som en textfil", "Fel filformat", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else if (fileSplit[fileSplit.Length - 1] == "rtf")
            {
                richTextBoxEditor.LoadFile(fileName, RichTextBoxStreamType.RichText);
            }
            else if (fileSplit[fileSplit.Length - 1] == "pdf")
            {
                richTextBoxEditor.Clear();

                PdfReader pdfread = new PdfReader(fileName);
                PdfReaderContentParser  pdfparser = new PdfReaderContentParser(pdfread);
                ITextExtractionStrategy strategy;

                for (int i = 1; i <= pdfread.NumberOfPages; i++)
                {
                    strategy = pdfparser.ProcessContent(i, new SimpleTextExtractionStrategy());
                    richTextBoxEditor.Text += strategy.GetResultantText();
                }
            }
            else if (fileSplit[fileSplit.Length - 1] == "txt")
            {
                richTextBoxEditor.LoadFile(fileName, RichTextBoxStreamType.PlainText);
            }
            else
            {
                richTextBoxEditor.LoadFile(fileName, RichTextBoxStreamType.PlainText);
            }

            textToolStripMenuItem.Enabled  = false;
            punktToolStripMenuItem.Enabled = false;
            textToolStripMenuItem.Checked  = false;
            punktToolStripMenuItem.Checked = false;
        }
예제 #2
0
        private void openFile(string fileName)
        {
            string[] fileSplit = fileName.Split('.');

            if (fileSplit[fileSplit.Length - 1] == "docx")
            {
                DocxToText dtt = new DocxToText(fileName);
                richTextBoxEditor.Text = dtt.ExtractText();
            }
            else if (fileSplit[fileSplit.Length - 1] == "doc")
            {
                MessageBox.Show("Tyvärr stödjer inte programmet det gamla wordformatet (.doc). Prova med att spara om det till det nya formatet (.docx), eller som en textfil", "Fel filformat", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else if(fileSplit[fileSplit.Length - 1] == "rtf")
            {
                richTextBoxEditor.LoadFile(fileName, RichTextBoxStreamType.RichText);
            }
            else if (fileSplit[fileSplit.Length - 1] == "pdf")
            {
                richTextBoxEditor.Clear();

                PdfReader pdfread = new PdfReader(fileName);
                PdfReaderContentParser pdfparser = new PdfReaderContentParser(pdfread);
                ITextExtractionStrategy strategy;

                for (int i = 1; i <= pdfread.NumberOfPages; i++)
                {
                    strategy = pdfparser.ProcessContent(i, new SimpleTextExtractionStrategy());
                    richTextBoxEditor.Text += strategy.GetResultantText();
                }
            }
            else if (fileSplit[fileSplit.Length - 1] == "txt")
            {
                richTextBoxEditor.LoadFile(fileName, RichTextBoxStreamType.PlainText);
            }
            else
            {
                richTextBoxEditor.LoadFile(fileName, RichTextBoxStreamType.PlainText);
            }

            textToolStripMenuItem.Enabled = false;
            punktToolStripMenuItem.Enabled = false;
            textToolStripMenuItem.Checked = false;
            punktToolStripMenuItem.Checked = false;
        }