阅读pdf文件详细信息和绑定到datagridview的问题 [英] read pdf files detailes and problem binding to the datagridview

查看:61
本文介绍了阅读pdf文件详细信息和绑定到datagridview的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我已经为pdf文件开发了winform应用程序并绑定到gridview



i已经读取了pdf文件和pdffullname(文件名路径)的内容但是我想知道如何读取文件名(不是文件的路径),大小,文件的扩展名和绑定问题





>
gridview .i已使用列表集合将文件的全名绑定到gridview但



gridview仅显示length属性。最后我想要pdfdetailes(filename ,尺寸,长度)和



解决绑定问题。



我的开发代码:



Actually i have develop winform app for pdf files detailes and bind to the gridview

i have read the content of pdf file and pdffullname(path of filename) but i want to how

to read filename(not path of file),size,extension of files and problem the binding the

gridview .i had binded the fullname of file using list collection to the gridview but

gridview shows the length attribute only .finally i want pdfdetailes(filename,size,length) and

slove the binding problem.

my developed code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.IO;
using form_app.Lib;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace form_app
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
          
        }
        public static string ExtractTextFromPdf(string filename)
        {
            using (PdfReader r = new PdfReader(filename))
            {
                StringBuilder text = new StringBuilder();

                for (int i = 1; i <= r.NumberOfPages; i++)
                {
                    text.Append(PdfTextExtractor.GetTextFromPage(r, i));
                }
                return text.ToString();
            };
        }
        private void button1_Click(object sender, EventArgs e)
        {
              List<string> filelist = new List<string>();
            
            string pathName = @"D:\Data Sets\Enron";

            string[] pdfFileNames = Directory.GetFiles(pathName, "*.pdf");
            MessageBox.Show(pdfFileNames.Length.ToString());

            foreach (string pdfFileName in pdfFileNames)
            {
              
                fileproperties fi = new fileproperties ();
                fi.fullname = pdfFileName;
                fi.content = ExtractTextFromPdf(pdfFileName);
                filelist.Add(fi.fullname);
            }
         
            dataGridView1.DataSource = filelist;
        } 

        }
    }





fileproperties.cs:





fileproperties.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace form_app.Lib
{
    class fileproperties
    {
        public long filesize { get; set; }
        public string filename { get; set; }
        public string fullname { get; set; }
        public string extension { get; set; }
        public string content { get; set; }
    }
}





请帮助我。



pls help me.

推荐答案

也许这个链接可以帮助你。


这篇关于阅读pdf文件详细信息和绑定到datagridview的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆