mgufrone / pdf-to-html

PDF to HTML PHP Class using Poppler-Utils
MIT License
175 stars 88 forks source link

How can i change image src path? #39

Open jadesenberg opened 7 years ago

jadesenberg commented 7 years ago

Hi guys is there a way that i can change the image src path in config?

img src="change this"

Thanks in advance

Dave-Morton commented 6 years ago

@jadesenberg I ran up against this as well, and found (part of ) a solution for this. I added the following PHP code to my script:

// change output file location
define('IMAGE_PATH', BASE_PATH . 'images' . DIRECTORY_SEPARATOR);
define('IMAGE_URL', BASE_URL . 'images/');
// BASE_PATH and BASE_URL set elsewhere in the script
list($fn, $ext) = explode('.', $filename);

Config::set('pdftohtml.output', IMAGE_PATH . "{$fn}/");

but that only solved half of the problem. The HTML and image output of the chosen PDF file now goes to the correct place, and would likely work if I were to header({location}) to the HTML page, but I'm using a viewer within an <iframe> element, so wish to echo the HTML instead. As such, when doing this, the location of the image's src ends up being wrong, so I also have to use the following code, too:

$content = str_replace('src="', 'src="' .  IMAGE_URL, $content);

it's a bit hacky, but it does work for what I need. I hope this proves useful to you. 😄