About drupal_realpath() and PDF Formatter The PDF Formatter module uses pdftohtml to transform PDF to HTML, and show information.

Changing the module code, it is possible to show images too, but the path used for the image in the HTML markup is wrong.

What can I do to fix it?

The code used by the module is the following.

// PDF to html formatter
case 'file_pdf_to_html_formatter':
  $pdftohtml_installed = pdf_formatter_pdftohtml_installed();
  foreach ($items as $delta =&gt; $item) {
    $html = '';
      $html = shell_exec('pdftohtml -q -stdout '.escapeshellarg(drupal_realpath($item['uri'])));
      // pdftohtml tends to generate too many non break spaces,
      // replace them with standard spaces
      $html = str_replace('&amp;nbsp;',' ',$html);

      // pdftohtml generates a complete HTML file.
      // Drupal only waits for contents between the body tag
      $html = preg_replace('/.*&lt;BODY[^&gt;]*&gt;(.*)&lt;\/BODY&gt;.*/si', '\\1', $html);
    }

    $element[$delta] = array('#markup' =&gt; $html);
  }
  break;


The output I get is the following.

&lt;img src="/var/www/html/drupal/sites/default/files/imgtest.jpg" /&gt;
To get the web-accessible URL for a local file, you should use file_create_url().

$html = shell_exec('pdftohtml -q -stdout '.escapeshellarg(file_create_url($item['uri'])));


Using it would probably not work, anyway: I think that pdftohtml first tries to access the local file to see if it is a PDF file, and it outputs what you see when the file is an image. I doubt that pdftohtml uses &lt;img /&gt; for every file that is not a PDF file or that is not able to access.
In your case, file_create_url('public://imgtest.jpg') would return $base_url/sites/default/files/imgtest.jpg where $base_url is the content of the global $base_url, which includes the http:// or https:// part. While that would be perfect to be used for the &lt;img /&gt; tag, it could not be used as filename, since pdftohtml is not probably able to handle a filename starting with http:// or https://. (In other words, it expects the filename of a local file.)

It is probably easier to check if the file is an image, and output the &lt;img&gt; tag using the output of file_create_url() as image URL in that case, or the output from pdftohtml when it is not an image.