Summary of reading PDF text under. NET

Source: Internet
Author: User

There are two main class libraries used to read PDF text in. NET: product_box and iTextSharp. Let's talk about consumer box first. This class library is said to be very powerful. Here I will just give a brief introduction: 1. Download consumer box 2. reference the dynamic link library to decompress the downloaded consumer box and find the Bin directory, the dll files to be referenced in the project are: IKVM. GNU. classpath. the dllPDFBox-0.7.3.dllFontBox-0.1.0-dev.dllIKVM.Runtime.dll references the above four files to the project and needs to introduce the following two namespaces in the file: using orgdomainbox. pdmodel; using orgdomainbox. util; 3. Code for using APIs: [csharp] using orgdomainbox. pdmodel; using orgdomainbox. util; public void 20172txt (FileInfo file, FileInfo txtfile) {PDDocument doc = PDDocument. load (file. fullName); inclutextstripper inclustripper = new inclutextstripper (); string text = inclustripper. getText (doc); StreamWriter swPdfChange = new StreamWriter (txtfile. fullName, false, Encoding. getEncoding ("gb2312"); swPdfChange. write (text); swPdfChange. close () ;}itextsharp is used to generate PDF files in many cases, but its ability to read PDF files is not bad. Use the following: 1. Download iTextSharp 2. reference the dynamic link library to decompress the itextsharp-dll-core.zip file in the downloaded package, obtain itextsharp. dll, add reference itextsharp in the project. dll to introduce the following three namespaces in the file: using iTextSharp; using iTextSharp. text; using iTextSharp.text.pdf; 3. Code for using APIs: [csharp] private string OnCreated (string filepath) {try {string pdffilename = filepath; pdfReader pdfReader = new PdfReader (pdffilename); int numberOfPages = pdfReader. numberOfPages; string text = string. empty; for (int I = 1; I <= numberOfPages; ++ I) {byte [] bufferOfPageContent = pdfReader. getPageContent (I); text + = System. text. encoding. UTF8.GetString (bufferOfPageContent);} www.2cto.com pdfReader. close (); return text;} catch (Exception ex) {StreamWriter wlog = File. appendText (System. appDomain. currentDomain. setupInformation. applicationBase + "\ mylog. log "); wlog. writeLine ("error file:" + e. fullPath + "Reason:" + ex. toString (); wlog. flush (); wlog. close (); return null ;}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.