Hello fellow monks,

I get the following error when I try to convert pdf to text using CAM::PDF

Expected string closing 4810 8.01.88 Td^M1.394.9zio...

Can someone help me either fix the error or make the script ignore the error and keep running?

Some pdfs are converted while some fail maybe it's a code that I get for pdf that only have pictures?

Here is the code

#!/usr/bin/perl -w use strict; use CAM::PDF; use CAM::PDF::PageText; use File::Spec::Functions; use File::Find::Rule; #1. Specify directory my $dirPath= 'F:/project_italia/firm_files'; my $src_fmt='*.*'; #2 retrieve all sub-dirs from the directory my @allDir = File::Find::Rule->maxdepth(1)->directory->in($dirPath); open(LIST, ">>", 'F:/project_italia/firmList_pdf.txt' ) or die "Can't +open destination.fil $!"; foreach (@allDir) { my $src_path = catfile($_, $src_fmt); my @filings = glob($src_path); foreach (@filings) { my $fileName=$_; my $pdf = CAM::PDF->new($_); #split path name my @textName = split(/\\/, $_); #Create new text file open(DEST, ">>", 'F:/project_italia/firm_text/'.$textName[4].'. +txt' ) or die "Can't open destination.fil $!"; #keeps track on whether the pdf to text conversion was successf +ul my $conv=0; my $count=0; #Get total page number of the pdf my $pageNum=$pdf->numPages(); for (1..$pageNum) { my $pageConv = $pdf->getPageContentTree($_); #if conversion fails move to the next file print DEST CAM::PDF::PageText->render($pageConv) or do { warn "PDF->new failed on $_\n"; next; }; $count++; #conversion is successful only when all pages have been co +nverted $conv=1 if ($count==$pageNum); } #close text file close DEST; #keep track of which files converted successfully print LIST "$textName[4] | $conv \n"; } } close LIST;

In reply to CAM::PDF error by eversuhoshin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.