title: PHP - Linking to html files is wrong in Pdf-to-html
body: <p>I have installed <code>Poppler Utils</code> for windows in addition to <a href="https://github.com/mgufrone/pdf-to-html" rel="nofollow">https://github.com/mgufrone/pdf-to-html</a></p>
  
  <p>It works perfectly and it converts <code>PDF files</code> to <code>HTML</code>, by making a single HTML file contains <strong>2</strong> iframes, one for <code>pages navigation</code> and the other for the <code>actual text</code>.</p>
  
  <p>The problem is when the <code>HTML</code> files are generated, the linking for <code>iframe src</code> gives a false linking.</p>
  
  <p>For Example:  </p>
  
  <ul>
  <li><p><code>Test.html</code></p></li>
  <li><p><code>Pages.html</code></p></li>
  <li><p><code>Page_1.html</code></p></li>
  </ul>
  
  <p>All these files exist in the same folder named "Output".</p>
  
  <p><code>Test.html</code> contains 2 <code>iframes</code> linking to <code>Pages.html</code> and <code>Page_1.html</code></p>
  
  <p>Here's the problem in <code>Test.html</code>:</p>
  
  <pre><code>&lt;frameset cols="100,*"&gt;
  &lt;frame name="links" src="output/Pages.html"/&gt;
  &lt;frame name="contents" src="output/Pages_1.html"/&gt;
  &lt;/frameset&gt;
  </code></pre>
  
  <p><strong>Should be:</strong></p>
  
  <pre><code>&lt;frameset cols="100,*"&gt;
  &lt;frame name="links" src="Pages.html"/&gt;
  &lt;frame name="contents" src="Pages_1.html"/&gt;
  &lt;/frameset&gt;
  </code></pre>
  
  <p><strong>PDF.php</strong></p>
  
  <pre><code>&lt;?php namespace Gufy\PdfToHtml;
  
  class Pdf
  {
    protected $file, $info;
    // protected $info_bin = '/usr/bin/pdfinfo';
    public function __construct($file, $options=array())
    {
      $this-&gt;file = $file;
      $class = $this;
      array_walk($options, function($item, $key) use($class){
        $class-&gt;$key = $item;
      });
      return $this;
    }
    public function getInfo()
    {
      if($this-&gt;info == null)
      $this-&gt;info($this-&gt;file);
      return $this-&gt;info;
    }
    protected function info()
    {
      $content = shell_exec($this-&gt;bin().' '.$this-&gt;file);
      // print_r($info);
      $options = explode("\n", $content);
      $info = array();
      foreach($options as &amp;$item)
      {
        if(!empty($item))
        {
          list($key, $value) = explode(":", $item);
          $info[str_replace(array(" "),array("_"),strtolower($key))] = trim($value);
        }
      }
      // print_r($info);
      $this-&gt;info = $info;
      return $this;
      // return $content;
    }
    public function html()
    {
      if($this-&gt;info == null)
      $this-&gt;info($this-&gt;file);
      return new Html($this-&gt;file);
    }
    public function getPages()
    {
      if($this-&gt;info == null)
      $this-&gt;info($this-&gt;file);
      return $this-&gt;info['pages'];
    }
    public function bin()
    {
      return Config::get('pdfinfo.bin', '/usr/bin/pdfinfo');
    }
  }
  </code></pre>
  
  <p><strong>Base.php</strong></p>
  
  <pre><code>&lt;?php
  namespace Gufy\PdfToHtml;
  
  class Base
  {
      private $options=array(
          'singlePage'=&gt;false,
          'imageJpeg'=&gt;false,
          'ignoreImages'=&gt;false,
          'zoom'=&gt;1.5,
          'noFrames'=&gt;true,
      );
      public $outputDir;
      private $bin="/usr/bin/pdftohtml";
      private $file;
  
      public function __construct($pdfFile='', $options=array())
      {
          if(empty($pdfFile))
              return $this;
          $pdf = $this;
          if(!empty($options))
          array_walk($options, function($value, $key) use($pdf){
              $pdf-&gt;setOptions($key, $value);
          });
          return $this-&gt;open($pdfFile);
      }
  
      public function open($pdfFile)
      {
          $this-&gt;file = $pdfFile;
          $this-&gt;setOutputDirectory(dirname($pdfFile));
          return $this;
      }
  
      public function html()
      {
          $this-&gt;generate();
          $file_output = $this-&gt;outputDir."/".preg_replace("/\.pdf$/","",basename($this-&gt;file)).".html";
          $content = file_get_contents($file_output);
          unlink($file_output);
          return $content;
      }
      /**
      * generating html files using pdftohtml software.
      * @return $this current object
      */
      public function generate(){
  
  
          $output = $this-&gt;outputDir."/".preg_replace("/\.pdf$/","",basename($this-&gt;file)).".html";
          $options = $this-&gt;generateOptions();
          $command = $this-&gt;bin()." ".$options." ".$this-&gt;file." ".$output;
          $result = exec($command);
          return $this;
  
      }
  
      /**
      * generate options based on the preserved options
      * @return string options that will be passed on running the command
      */
      public function generateOptions()
      {
          $generated = array();
          array_walk($this-&gt;options, function($value, $key) use(&amp;$generated){
              $result = "";
              switch($key)
              {
                  case "singlePage":
                  $result = $value?"-c":"-s";
                  break;
                  case "imageJpeg":
                  $result = "-fmt ".($value?"jpg":"png");
                  break;
                  case "zoom":
                  $result = "-zoom ".$value;
                  break;
                  case "ignoreImages":
                  $result = $value?"-i":"";
                  break;
                  case 'noFrames':
                  $result = $value?'-noframes':'';
                  break;
              }
              $generated[] = $result;
          });
          return implode(" ", $generated);
      }
  
      /**
      * change value of preserved configuration
      * @param string $key key of option you want to change
      * @param mixed $value value of option you want to change
      * @return $this current object
      */
      public function setOptions($key, $value)
      {
          if(isset($this-&gt;options[$key]))
              $this-&gt;options[$key] = $value;
          return $this;
      }
      /**
      * open pdf file that will be converted. make sure it is exists
      * @param string $pdfFile path to pdf file
      * @return $this current object
      */
      public function setOutputDirectory($dir)
      {
          $this-&gt;outputDir=$dir;
          return $this;
      }
      /**
      * clear the whole files that has been generated by pdftohtml. Make sure directory ONLY contain generated files from pdftohtml
      * because it remove the whole contents under preserved output directory
      * @return $this current object
      */
      public function clearOutputDirectory()
      {
          $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this-&gt;outputDir, \FilesystemIterator::SKIP_DOTS));
          foreach($files as $file)
          {
              $path = (string)$file;
              $basename = basename($path);
              if($basename != '..')
              {
                  if(is_file($path) &amp;&amp; file_exists($path))
                      unlink($path);
                  elseif(is_dir($path) &amp;&amp; file_exists($path))
                      rmdir($path);
              }
          }
          return $this;
      }
  
      public function bin()
      {
          return Config::get('pdftohtml.bin', '/usr/bin/pdftohtml');
      }
  }
  </code></pre>