First, download PDFBox
Visit URL http://sourceforge.net/projects/pdfbox/(This is definitely a good site)
Ii. referencing the dynamic link library
To extract the downloaded PDFBox, locate the bin directory in which the referenced DLL file needs to be added in the project:
IKVM. Gnu. Classpath.dll
Pdfbox-0.7.3.dll
Fontbox-0.1.0-dev.dll
IKVM. Runtime.dll
Reference the above 4 files to the project, you need to introduce the following 2 namespaces in the file:
Using Org.pdfbox.pdmodel;
Using Org.pdfbox.util;
Third, the use of the API method
usingSystem.IO;usingSystem.Text;usingOrg.pdfbox.pdmodel;usingOrg.pdfbox.util;namespacepdfreader{classProgram { Public Static voidPdf2txt (FileInfo pdffile, FileInfo txtfile) {pddocument doc=Pddocument.load (pdffile. FullName); Pdftextstripper Pdfstripper=NewPdftextstripper (); stringText =Pdfstripper.gettext (DOC); StreamWriter Swpdfchange=NewStreamWriter (txtfile. FullName,false, Encoding.GetEncoding ("gb2312")); Swpdfchange.write (text); Swpdfchange.close (); } Static voidMain (string[] args) {Pdf2txt (NewFileInfo (@"c:/users/susan/desktop/Full draft __ hurried that year _ Nine night anise. pdf"),NewFileInfo (@"c:/users/susan/desktop/Full draft __ hurried that year _ Nine night anise .")); } }}
C # read PDF document content