using System;
using System.IO;
using iTextSharp.text.pdf;

namespace PdfToText
{
    
/// <summary>
    
/// Parses a PDF file and extracts the text from it.
    
/// </summary>

    public class PDFParser 
    
{
        
/// BT = Beginning of a text object operator 
        
/// ET = End of a text object operator
        
/// Td move to the start of next line
        
///  5 Ts = superscript
        
/// -5 Ts = subscript


        
Fields

        
ExtractText

        
ExtractTextFromPDFBytes

        
CheckToken
    }

}


usage:
using System;
using System.Text;
using System.IO;

namespace PdfToText
{
    
/// <summary>
    
/// The main entry point to the program.
    
/// </summary>

    class Program
    
{
        
static void Main(string[] args)
        
{
            
try
            
{
                
if (args.Length < 1)
                
{
                    DisplayUsage();
                    
return;
                }


                
string file = args[0];
                
if (!File.Exists(file))
                
{
                    file 
= Path.GetFullPath(file);
                    
if (!File.Exists(file))
                    
{
                        Console.WriteLine(
"Please give in the path to the PDF file.");
                    }

                }


                PDFParser pdfParser 
= new PDFParser();
                pdfParser.ExtractText(file, Path.GetFileNameWithoutExtension(file)
+".txt");
            }

            
catch (Exception exc)
            
{
                Console.WriteLine(exc);
            }

        }


        
static void DisplayUsage()
        
{
            Console.WriteLine();
            Console.WriteLine(
"Usage:\tpdftotext FILE");
            Console.WriteLine();
            Console.WriteLine(
"\tFILE\t the path to the PDF file, it may be relative or absolute.");
            Console.WriteLine();
        }

    }

}


问题,不支持中文,没有布局,仅仅是把每页的所以文字抽取出来,如果想真正实现PDFtoTxt,仍然有好多路要走,但毕竟是个好的开始。

from http://www.codeproject.com/useritems/PDFToText.asp
posted on 2006-06-16 07:26  RubyPDF  阅读(8948)  评论(8编辑  收藏  举报