Convert PDF to TXT to extract Chinese Characters

Source: Internet
Author: User

The following reading method may cause gibberish reading of some PDF files. If you have any other solutions, you can learn them together.

 

Winform code

First, download: product_box

By referencing two dll:
Ikvm. GNU. classpath. dll
PDFBox-0.7.3.dll

Put the two DLL files in the bin directory of the project:
FontBox-0.1.0-dev.dll
Ikvm. runtime. dll

// The referenced space, which can be used only after the dynamic DLL consumed by the Project
Using orgdomainbox. pdmodel;
Using orgdomainbox. util;

// Code in the button event
Private void button2_click (Object sender, system. eventargs E)
{

Pddocument txttmp = pddocument. Load (physical file path)
Extends textstripper extends stripper = new extends textstripper ();
Textbox1.text = javasstripper. gettext (txttmp );
Textbox1.text + = textbox1.text. length;

/* For future reference
Dialogresult DR = folderdialog. showdialog ();
If (Dr! = Dialogresult. OK)
{
Return;
}
// Select the file path
Folderpath = folderdialog. selectedpath;

Directoryinfo dirpdf = new directoryinfo (folderpath );
If (! Dirpdf. exists)
{
MessageBox. Show ("the file path you entered is incorrect. Please verify it! ");
Return;
}

Fileinfo [] fileoldsystem = dirpdf. getfiles ("*. pdf ");
If (fileoldsystem. Length = 0)
{
MessageBox. Show ("the file path you selected does not have a PDF file. Please verify it! ");
Return;
}

Foreach (fileinfo file in fileoldsystem)
{
Pddocument txttmp = pddocument. Load (file. fullname. tolower ());
Extends textstripper extends stripper = new extends textstripper ();
Textbox1.text = javasstripper. gettext (txttmp );
Textbox1.text + = textbox1.text. length;

Streamwriter Sw = file. appendtext (file. fullname. tolower (). Replace (". pdf", ". txt "));
Sw. Write (textbox1.text );
Sw. Flush ();
Sw. Close ();

}

*/

}

 

 

 

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.