Menu

#247 Error creating PDF image object: Can't call method "val" on an undefined value

v1.0_(example)
closed-fixed
nobody
None
5
2018-09-23
2017-04-23
No

Occasionally when saving a scan to PDF, I get the attached error message and the PDF file does not save. The progress bar in the status area gets stuck until I take another action (such as retrying the save). Sometimes when I retry saving the file it works, other times it doesn't and I have to restart gscan2pdf (which is irritating when I've made a multi-page scan I then can't save).

1 Attachments

Discussion

  • Stephen Kent

    Stephen Kent - 2017-04-23

    Forgot to mention, this is in gscan2pdf 1.5.4. I tried to reproduce this with gscan2pdf --log=log, but was unable to do so. This error is nondeterministic and doesn't happen every time, even with the same scan. I do not know how to reliably reproduce it.

     
  • Jeffrey Ratcliffe

    The error is being reported by PDF::API2, and just passed on by gscan2pdf. However, I can't expect the maintainer ot PDF::API2 to fix it without being able to reproduce it.

    Please start gscan2pdf from the command line with the --log=log option, reproduce the problem, quit, and post the log file and the image that triggered the error.

    I appreciate that you can't reliably reproduce the problem, but if you start gscan2pdf with the above options, until it pop us again, then I at least have a fighting chance of finding the problem.

    I have never seen this error.

     
  • Stephen Kent

    Stephen Kent - 2017-06-12

    I've been running gscan2pdf with logging enabled for a while now and this error happened again. It looks like gscan2pdf is looking for a nonexistent file in its temp directory. Here's the end of the log:

    DEBUG - non-ascii text is 'fi' in 'fi'
    WARN - Wide character in print at /usr/share/perl5/Log/Log4perl/Appender/Screen.pm line 39.
    
    WARN - Wide character in print at /usr/share/perl5/Log/Log4perl/Appender/File.pm line 245.
    
    DEBUG - non-ascii text is '’' in 'taeetti'
    WARN - Wide character in print at /usr/share/perl5/Log/Log4perl/Appender/Screen.pm line 39.
    
    WARN - Wide character in print at /usr/share/perl5/Log/Log4perl/Appender/File.pm line 245.
    
    DEBUG - non-ascii text is 'fi' in 'tarkanfii'
    WARN - Wide character in print at /usr/share/perl5/Log/Log4perl/Appender/Screen.pm line 39.
    
    INFO - Added /tmp/gscan2pdf-6WyJ/6jKabdg4FO.jpg at 300 PPI
    WARN - Exception 435: unable to open image `/tmp/gscan2pdf-6WyJ/tWH_jJfUm2.pnm': No such file or directory @ error/blob.c/OpenBlob/2641
    WARN - Use of uninitialized value in division (/) at /usr/share/perl5/Gscan2pdf/Document.pm line 2851.
    
    WARN - Use of uninitialized value in division (/) at /usr/share/perl5/Gscan2pdf/Document.pm line 2852.
    
    INFO - Depth of /tmp/gscan2pdf-6WyJ/tWH_jJfUm2.pnm is 16
    WARN - Use of uninitialized value $type in concatenation (.) or string at /usr/share/perl5/Gscan2pdf/Document.pm line 2868.
    
    INFO - Type of /tmp/gscan2pdf-6WyJ/tWH_jJfUm2.pnm is 
    WARN - Use of uninitialized value $type in pattern match (m//) at /usr/share/perl5/Gscan2pdf/Document.pm line 2869.
    
    INFO - Selecting png compression
    INFO - Converting /tmp/gscan2pdf-6WyJ/tWH_jJfUm2.pnm to /tmp/gscan2pdf-6WyJ/bdriOFEFF_.png
    INFO - Writing temporary image /tmp/gscan2pdf-6WyJ/bdriOFEFF_.png
    WARN - Exception 410: no images defined `Image::Magick' @ error/Magick.xs/XS_Image__Magick_Write/14009
    INFO - Defining page at 0pt x 0pt
    WARN - Can't call method "val" on an undefined value at /usr/share/perl5/PDF/API2/Resource/XObject/Image.pm line 66.
    
    ERROR - Error creating PDF image object: Can't call method "val" on an undefined value at /usr/share/perl5/PDF/API2/Resource/XObject/Image.pm line 66.
    
     
  • Jeffrey Ratcliffe

    Is this still with v1.5.4? Can you upgrade to a newer version? Can you attach the complete log file next time, along with the contents of the temporary directory? If you don't want to put the images on the internet, can you at least send them directly to me, and post the ls -l for the temporary directory?

     
  • Stephen Kent

    Stephen Kent - 2017-07-23

    This was on gscan2pdf version 1.8.0. I'll see what I can provide the next time this happens; most of the documents I scan can't be posted publicly on the internet.

     
  • Jeffrey Ratcliffe

    Rather than pasting the messages from the terminal, would you mind posting the complete log file? That way I can see where the errors started.

    The non-ascii text and wide character messages are cosmetic, but the stuff afterwards shouldn't happen, and is a problem with gscan2pdf, not with PDF::API2.

    I assume that this only happens when scanning? Have you ever encountered this when importing from a file?

     
  • Faheem Mitha

    Faheem Mitha - 2018-07-30

    I've just started seeing this with 2.1.3-1.

    I was scanning an unusually large (and perhaps slightly complex) document fo 36 pages in color. I don't usually try to scan something so large. The file saved is essentially blank - 15 bytes, I think.

    ls -lah upstox_form_annot_color_scanned.150dpi.pdf
    -rw-r--r-- 1 faheem faheem 15 Jul 30 16:13 upstox_form_annot_color_scanned.150dpi.pdf

    Cat shows me something like this:

    %PDF-1.4
    %��͵

    I just saw this error. I'll try to get a log file and post if I see anything that looks useful.

     
  • Faheem Mitha

    Faheem Mitha - 2018-07-30

    I attach a gzip of the log. It's quite large, over 5 MB.

    Note that I have tesseract running, and it seems to be really busy trying to do stuff.

     
  • Jeffrey Ratcliffe

    It looks to me from Faheem's log as though tesseract has not finished when the save to PDF process is started. The tesseract process then finishes, creating a new page, and the old page then no longer exists when the save to PDF process tries read it.

    In short - a race condition.

    The solution is tricky, as reproducing it is not easy, but having found a way of reproducing it:

    • either drop the usage of unique temporary names for each page
    • or keep track of which pages are being worked on and only pass those pages to the queue when all preceding processes have finished.
    • or only pass a reference to the pages to be processed, and fetch the pages themselves when the process can start.

    I think I like the last one the best.

     
  • Faheem Mitha

    Faheem Mitha - 2018-07-31

    Hi Jeffrey,

    Thank you for the response.

    So the tesseract process changes the filenames? Can you elaborate a little on how this works?

    In my particular example, tesseract seems to be working really hard scanning those pages. I have an excessive number of tabs open in Chromium, so that may be affecting my memory usage - I'm not sure.

    In any case, if tesseract is causing a problem, at least this provides a simple workaround. I.e. turn off tesseract.

    If you are interested, the document I was scanning is the account opening form for a discount broker called Upstox. I can probably send you a blank version of this form if you would find it useful. Or send you a link to it.

     
  • Jeffrey Ratcliffe

    Yes - any process that modified any part of the page - image or OCR layer - modifies the temporary files for that page. Even if I kept the image filename for tesseract, the race condition would prevent the OCR layer from being added to the PDF or DjVu.

    The workaround until I have a proper fix is not to set off the save process until all other processes have finished.

     
  • Jeffrey Ratcliffe

    I have a fix for this now. You'll see it in the next release. If you are interested in testing it, I can attach a .deb here.

     

    Last edit: Jeffrey Ratcliffe 2018-08-14
  • Jeffrey Ratcliffe

    • status: open --> closed-fixed
     
  • Faheem Mitha

    Faheem Mitha - 2018-08-28

    Hi Jeffrey,

    If a release isn't happening any time soon, sure, please upload a deb with the fix. I'm on AMD64 if that matters. Also, can you describe what fix you eventually came up with? Just curious.

     
  • Jeffrey Ratcliffe

    Try this. It implements the last of my ideas, only passing a reference to the pages to be processed, and fetches the pages themselves when the process can start.

     
  • Faheem Mitha

    Faheem Mitha - 2018-09-22

    Hi Jeffrey,

    I see that #247 is listed as fixed by 2.1.5, but this is still open.

     
  • Jeffrey Ratcliffe

    What do you mean by "still open"? I closed this bug on 2018-08-14.

     
  • Faheem Mitha

    Faheem Mitha - 2018-09-23

    So you did. Sorry, I must be losing my mind.

     

Log in to post a comment.

MongoDB Logo MongoDB