#!/usr/bin/perl -w
use strict;
use HTML::TokeParser::Simple;
my $file = $ARGV[0]; # base file name (no extension)
my $pdf = "$file.pdf"; # the pdf file to fix
my $txt = "$file.txt"; # the file to export as text
my $pdf2html = "pdftohtml.exe"; # the executable to create the html
my $html = "$file.html"; # the html file to create
system("$pdf2html -noframes $pdf"); # create the html file
my $p = HTML::TokeParser::Simple->new($html); # create the html parser
open(TXT, ">", $txt) || die "Cannot open $txt, "; # create the text file
while (my $token = $p->get_token) {
# print TXT "\n" if ($token->is_start_tag('br')); # may be needed for some files
next if ! $token->is_text; # skip to next token if it's not text
my $text = $token->return_text;
$text =~ s/&/&/g; # add any html filters here
print TXT $text;
}
close(TXT);