访问c#中的pdf文件属性 [英] access pdf file properties in c#

查看:195
本文介绍了访问c#中的pdf文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了winform应用程序,用于访问pdf属性,如文件名和完整路径



文件,大小,扩展名,pdf file.alredy的内容我正在访问路径的文件和内容



的pdf文件然后我想要重新属性文件名,大小,扩展名





重要提示:文件类对于fileinfoarray非常有用,但我没有使用fileinfo数组i



我只使用字符串数组。不是告诉我们使用File class.it对filname,size,extensions没用。文件类没有访问扩展名,文件名,大小的方法。如果没有方法,那么



接近将在那里告诉我。



i have develop winform app for accessing pdf properties like filename and full path of

file,size,extension,content of pdf file.alredy i am accessing path of file and content

of pdf file then i want remaing properties like filename,size,extension


Important:File class is useful for fileinfoarray but i am not using fileinfo array i

am using string array only.pls don't tell to use File class.it is not useful for filname,size,extensions.File class have no method for access extension,filename,size.if any

approaches will be there tell me.

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 System.IO;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.Windows.Forms;
using pdf_app.Lib;

namespace pdf_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)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.CheckFileExists = true;
            openFileDialog.AddExtension = true;
            openFileDialog.Multiselect = true;
            openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
            DialogResult result = openFileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string[] files = openFileDialog.FileNames;
            }
            foreach (string access in openFileDialog.FileNames)
            {
                fileatt f = new fileatt();
                f.fFullName = access;
                f.fContent = ExtractTextFromPdf(access);
            }
        }



fileatt类如:


fileatt class like :

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

namespace pdf_app.Lib
{
    class fileatt
    {
        public long FileSize { get; set; }
        public string fName { get; set; }
        public string fFullName { get; set; }
        public string fExtension { get; set; }
        public string fContent { get; set; }
    }
}





i想要保留文件名,大小,扩展名等属性



请帮助我。



i want remaing properties like filename,size,extension

pls help me.

推荐答案

您之前的帖子上的问题没有得到正确回答。我相信海报应该引导你到文件信息 [ ^ ]
The question was not answered correctly on your previous post. I believe the poster should have directed you to the FileInfo class[^]


这篇关于访问c#中的pdf文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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