in reply to Extracting the data from a PDF
Okay, it's not great but it is a good start. It works for some of the PDF files that I have but not all of them. If the PDF file contains columns of data the output from pdf2html is terrible.
As always YMMV.
#!/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 fi +le 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);
|
|---|