Convert a pdf document to a txt file word document,

private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            string filepath;
            dlg.Filter = "PDF Files(*.PDF)|*.PDF|All Files (*.*)|*.*";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                filepath = dlg.FileName.ToString();

                string strtext = string.Empty;
                try
                {

                    PdfReader reader = new PdfReader(filepath);
                    for (int page = 1; page <= reader.NumberOfPages; page++)
                    {
                        //PdfDictionary PageDictionary = reader.GetPageN(page);
                        //PdfArray Annots = PageDictionary.GetAsArray(PdfName.ANNOTS);
                        ////var Links =Annots
                        ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
                        string s = PdfTextExtractor.GetTextFromPage(reader, page, its);
                        s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
                        //if(Annots!=null)
                        strtext = strtext + s;
                        richTextBox1.Text = strtext;
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {

                    MessageBox.Show(ex.Message);
                }
            }
            StreamWriter File = new StreamWriter("E:\\" + dlg.SafeFileName.Split('.')[0] + DateTime.Now.Millisecond + ".doc" + "");
            File.Write(richTextBox1.Text);
            File.Close();

        }

Comments

Popular posts from this blog

My Interview Experience

React Checkbox Control SPFx