Scanned Documents Dispatch not working

jessenewsome wrote on Sunday, April 15, 2012:

I’m running xampp and 4.1, I have put both pdf and tif files in the scanned doc directory but when I hit dispatch I get no images or page numbers to select in either the pdf files or tif files. If I hit ok a popup error says No Pages Selected

Here’s our goal.  We are 95% paperless and fax in some docs.  I can store these faxed in docs in the scanned dir and they show up in emr Fax/Scan however we can’t dispatch them to a patient.

I’ve been searching and it may be because I’m running windows.

Is there a developer who can rewrite the dispatch.php to handle pdf files instead of tif?  all our users are remote and downloading even a 5pg tif could be 20mb or more just to preview and select pages to dispatch.

any ideas?

penguin8r wrote on Monday, April 16, 2012:

We looked into processing PDFs.  It’s theoretically possible (not easy, but possible) to modify the fax_dispatch.php to allow you to store whole PDF files into patient charts.  To split the PDFs into pages, & allow you to file them a page or group of pages at a time, is nearly impossible (at least on Linux), maybe if you bought the right software on Windows you could paginate the PDF files, , but to do all that & run it inline in a browser window would be an impressive feat.  Tif files, ugly as they are, at least can be processed in the background & separated into pages.  Hopefully somebody will have a suggestion, we do all our back ends on Linux, in this case it may be that there is a Windows software package out there that can help.

tmccormi wrote on Tuesday, April 17, 2012:

You can manipualte PDF in Linux very well with pdftk, it like imagemagik for PDF files …
We use it a lot to create PDF files that can be filled by external data (like signatures … fer instance)

-Tony

DESCRIPTION
       If  PDF  is  electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses.  Pdftk is a simple tool
       for doing everyday things with PDF documents.  Use it to:

       * Merge PDF Documents
       * Split PDF Pages into a New Document
       * Rotate PDF Documents or Pages
       * Decrypt Input as Necessary (Password Required)
       * Encrypt Output as Desired
       * Fill PDF Forms with X/FDF Data and/or Flatten Forms
       * Generate FDF Data Stencil from PDF Forms
       * Apply a Background Watermark or a Foreground Stamp
       * Report PDF Metrics such as Metadata and Bookmarks
       * Update PDF Metadata
       * Attach Files to PDF Pages or the PDF Document
       * Unpack PDF Attachments
       * Burst a PDF Document into Single Pages
       * Uncompress and Re-Compress Page Streams
       * Repair Corrupted PDF (Where Possible)

xiaoanri wrote on Wednesday, March 27, 2013:

Regarding manipulating PDF files, we have found it is easy to do with a windows PDF file printer, just select which pages to print out togather and save as new file.  It has to be done on a windows station unfortunately. 

The fax/scanned document dispatch function is not working well on 4.1.1 either.  i tried to put the files in a samba folder and direct the openemr scan folder there.  The documents all show up in OpenEMR, and it even loads all the PDF pages in the dispatch window, but when attempting to dispatch to a patient’s document folder, it returns : “tiff2pdf returns 1:” on a white screen.   If I choose to upload as a scanned encounter note, it would return a path : “/var/www/openemr/sites/default/documents/2/encounters” on a white page.

I also found the postfix of the file name, such as “.pdf” or “.tiff” are all stripped in the faxcache/scan folder, although they are intact in samba folder.  would this have anything to do with it ?  Thank you.

xiaoanri wrote on Wednesday, March 27, 2013:

when attempting to dispatch a tiff file, it also give me the same “no page selected” error msg.  but the tiff file does not show up in the dispatch window at all.

sunsetsystems wrote on Wednesday, March 27, 2013:

Sounds like you are missing tiff2pdf and maybe some other dependencies.  This thread pretty much applies, see the last few postings there:

https://sourceforge.net/projects/openemr/forums/forum/202504/topic/1410806

Rod
www.sunsetsystems.com

xiaoanri wrote on Thursday, March 28, 2013:

Rod, thank you for your help. I did check the files, the libtiff-tools package was installed already,  I also confirmed all the three files tiff2pdf, tiffcp and tiffsplit all exist. are there any permission issues?  I have already set the sites/default/document folder to 777.  

xiaoanri wrote on Thursday, March 28, 2013:

also, in the fax_dispatch.php file, i found this part  to convert tiff file to pdf:

// Create the target PDF.  Note that we are relying on the .tif files for
      // the individual pages to already exist in the faxcache directory.
      //
      $info_msg .= mergeTiffs();
      // The -j option here requires that libtiff is configured with libjpeg.
      // It could be omitted, but the output PDFs would then be quite large.
      $tmp0 = exec(“tiff2pdf -j -p letter -o ‘$target’ ‘$faxcache/temp.tif’”, $tmp1, $tmp2);

      if ($tmp2) {
        $info_msg .= "tiff2pdf returned $tmp2: $tmp0 ";
      }
      else {
        $newid = generate_id();
        $fsize = filesize($target);
        $catid = (int) $_POST;
        // Update the database.
        $query = "INSERT INTO documents ( " .
          “id, type, size, date, url, mimetype, foreign_id, docdate” .
          " ) VALUES ( " .
          "’$newid’, ‘file_url’, ‘$fsize’, NOW(), ‘file://$target’, " .
          "‘application/pdf’, $patient_id, ‘$docdate’ " .
          “)”;
        sqlStatement($query);
        $query = "INSERT INTO categories_to_documents ( " .
          “category_id, document_id” .
          " ) VALUES ( " .
          "’$catid’, ‘$newid’ " .
      if ($tmp2) {
        $info_msg .= "tiff2pdf returned $tmp2: $tmp0 ";
      }
      else {
        $newid = generate_id();
        $fsize = filesize($target);
        $catid = (int) $_POST;
        // Update the database.
        $query = "INSERT INTO documents ( " .
          “id, type, size, date, url, mimetype, foreign_id, docdate” .
          " ) VALUES ( " .
          "’$newid’, ‘file_url’, ‘$fsize’, NOW(), ‘file://$target’, " .
          "‘application/pdf’, $patient_id, ‘$docdate’ " .
          “)”;
        sqlStatement($query);
        $query = "INSERT INTO categories_to_documents ( " .
          “category_id, document_id” .
          " ) VALUES ( " .
          "’$catid’, ‘$newid’ " .
          “)”;
        sqlStatement($query);
      } // end not error

Does this need modification since the file is already pdf format?

sunsetsystems wrote on Thursday, March 28, 2013:

PDFs are already handled.  What you might do is look at the code to determine what the full command line is for the tiff2pdf command, then execute it yourself from a terminal window and see what error is produced.  Come to think of it, it would be very helpful is the error message in OpenEMR displays the full command line.

Rod
www.sunsetsystems.com

xiaoanri wrote on Thursday, March 28, 2013:

thank you, Rod.  i tried to execute the command:

tiff2pdf -j -p letter -o ‘$target’ ‘$faxcache/temp.tif’

and get this: TIFFOpen: $faxcache/temp.tif: Cannot open.
tiff2pdf: Can’t open input file $faxcache/temp.tif for reading.

the faxcache is already made 777, and there is no any files other than  a “scan” folder.   does that mean the temp.tif is not generated properly, or something else?

sunsetsystems wrote on Thursday, March 28, 2013:

$target and $faxcache are PHP variables, you have to substitute them with whatever their values are.

Try changing these lines:

$tmp0 = exec(“tiff2pdf -j -p letter -o ‘$target’ ‘$faxcache/temp.tif’”, $tmp1, $tmp2);
if ($tmp2) {
  $info_msg .= "tiff2pdf returned $tmp2: $tmp0 ";
}

to instead be:

$cmd = “tiff2pdf -j -p letter -o ‘$target’ ‘$faxcache/temp.tif’”;
$tmp0 = exec($cmd, $tmp1, $tmp2);
if ($tmp2) {
  die(text(“This command failed: $cmd”));
}

Hopefully that will tell you in the error message what the command is.

Rod
www.sunsetsystems.com

xiaoanri wrote on Thursday, March 28, 2013:

Rod, after the change, the error message shows:

This command failed: tiff2pdf -j -p letter -o ‘/var/www/openemr/sites/default/documents/2/testing–_16.pdf’ ‘/var/www/openemr/sites/default/faxcache/scan/testing–/temp.tif’

sunsetsystems wrote on Thursday, March 28, 2013:

OK good, now what happens if you run that at the server’s command line?

Rod
www.sunsetsystems.com

xiaoanri wrote on Thursday, March 28, 2013:

it shows the same as it was-not able to open temp.tif file: 

TIFFOpen: $faxcache/temp.tif: Cannot open.
tiff2pdf: Can’t open input file $faxcache/temp.tif for reading.

sunsetsystems wrote on Thursday, March 28, 2013:

1. Check if /var/www/openemr/sites/default/faxcache/scan/testing–/temp.tif exists.

2. The message should not include the text “$faxcache”.  I wanted you to copy in this at the command prompt:
tiff2pdf -j -p letter -o ‘/var/www/openemr/sites/default/documents/2/testing–_16.pdf’ ‘/var/www/openemr/sites/default/faxcache/scan/testing–/temp.tif’

Rod
www.sunsetsystems.com

xiaoanri wrote on Thursday, March 28, 2013:

sorry i misunderstood you.  

1- the temp.tif is in the folder

2-after executing the command, it shows:

tiff2pdf: No support for /var/www/openemr/sites/default/faxcache/scan/testing–/temp.tif with 16 bits per sample.
tiff2pdf: An error occurred creating output PDF file.

sunsetsystems wrote on Thursday, March 28, 2013:

Now we’re getting somewhere.  tiff2pdf does not like your TIFF image format.  Can you get your scanner to output with 8-bit or less color depth?

Rod
www.sunsetsystems.com

xiaoanri wrote on Thursday, March 28, 2013:

The original file was PDF, and it seems when i try to dispatch, the program will generate a temp.tff and put it down in the faxcache/scan/<filename> folder, along with some other files.  the tiff2pdf program will then try to convert it back to pdf file again. 

So i am guessing there is some where in the dispatch.php code that defines the output file charactor?  I will try to look at it now and report back.

xiaoanri wrote on Thursday, March 28, 2013:

Rod, on checking the fax_dispatch.php file, i can only find a tiffcp command, is this the one to convert pdf to tiff?  am i missing the key factor here.  i also tried to find the available options for tiffcp here:

http://linux.about.com/library/cmd/blcmdl1_tiffcp.htm

but not able to find the one that defines the bit depth.  what should be done from here on? Thank you!

sunsetsystems wrote on Thursday, March 28, 2013:

Here’s the line that converts the pdf to tiff format:

    $tmp0 = exec(“convert -density 203x196 ‘$filepath’ ‘$faxcache/deleteme.tif’”, $tmp1, $tmp2);

You might try changing it to:

    $tmp0 = exec(“convert -density 203x196 ‘$filepath’ -depth 8 ‘$faxcache/deleteme.tif’”, $tmp1, $tmp2);

Note the tiff images are cached in /var/www/openemr/sites/default/faxcache/scan so you’ll need to clear out that directory first.

If that doesn’t work, then again, try setting the scanner to 8-bit color depth (256 colors).  Or set it to B&W as a test.

Rod
www.sunsetsystems.com