如何将pdf文件转换为字符串 [英] How to convert pdf file into string

查看:217
本文介绍了如何将pdf文件转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,我有一个文件上传控件,当选择文件然后当用户点击按钮我使用ItextSharp将页面竞争转换为字符串时,这可以在窗体表单应用程序中轻松完成使用以下代码

i have a web application, i have a file upload control,when file is selected then when user click on a button i am using ItextSharp to convert it page contend into string,this can be easily done in window form application using following code

OpenFileDialog ofd = new OpenFileDialog();
           string filePath;
           //  string file;
           ofd.Filter = "PDF Files(*.pdf)|*.PDF|ALL Files(*.*)|*.*";
           if (ofd.ShowDialog() == DialogResult.OK)
           {

               filePath = ofd.FileName.ToString();
               PdfReader reader = new PdfReader(filePath);



如何在网络应用程序中执行相同操作?使用FileUPLOAD CONTROL?PLZ


how can i do same in web application?using FileUPLOAD CONTROL?PLZ

推荐答案

FileUpload Control不会传递给你一个文件 - 它会传递一个字节流 - 所以你需要查看你的PdfReader类构造函数,看看是否有一个带有Stream,一个字节数组或一串数据的重载而不是一个字符串路径。

然后你可以适当地转换数据并将其传递给构造函数。



如果班级只接受一个文件的路径,然后你需要在它周围kludge并创建一个临时文件,编写你要做的数据,打开你的PDF,处理它,然后关闭并删除临时文件。令人讨厌,如果出现任何问题,容易留下大型临时文件铺设,所以你也需要一种机制来清除那些......
The FileUpload Control does not pass you a file - it passes you a stream of bytes - so you need to look at your PdfReader Class constructor to see if there is an overload that takes a Stream, an array of bytes, or a string of data rather than a string path.
You can then convert the data appropriately and pass it to the constructor.

If the class only accepts a path to a file, then you will need to kludge round it and create a temporary file, write your data to do, open your PDF, process it, then close and delete the temporary file. Nasty, and prone to leaving large temporary documents "laying around" if anything goes wrong, so you'll want a mechanism for clearing those up as well...


这篇关于如何将pdf文件转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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