I'm using tinymce with image upload using the package "laravel-tinymce-simple-imageupload". When the user enters some content in the textarea and clicks the form submit button I want to put the content in the textarea in a pdf file. I have the code below.
The issue is that in the pdf file, if is inserted an image in the textarea, the image doesn't appear in the pdf and in the pdf appears "Image not found or type unknown".
Do you know what can be the issue?
The image is stored like this in the content column of the certificates table:
<p>test<img src="/img/image_15zdbBr.jpeg" alt="" width="1200" height="900" /></p>
Code to get the pdf:
$certificateContent = RegistrationType::with('certificate')->where('id', $request->registrationType)->first();
$pdf = app()->make('dompdf.wrapper');
$pdf->loadHTML($certificateContent->certificate->content);
return $pdf->download('test.pdf');
Tinymce code has relative_urls as false:
tinymce.init({
selector:'textarea',
plugins: 'image code link',
relative_urls: false,
file_browser_callback: function(field_name, url, type, win) {
// trigger file upload form
if (type == 'image') $('#formUpload input').click();
}
});
I already use "setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])" but also dont works with that, it show the same error.
It seems that the issue can be because is necessary to change the url path of the image. But Im not understanding how to do that since the user only selects a image in the the tinymce textarea how to change the absolute path of that image.
This is a reported issue: https://github.com/dompdf/dompdf/issues/1659 .
Suggest you:
img/image_15zdbBr.jpeg
, and$dompdf->setBasePath($base_path)
where $base_path is where the files sit. (https://github.com/dompdf/dompdf/wiki/Usage#setbasepath)Edit with salient bits from chat:
$pdf->getDomPDF()->setBasePath();
../../../image/file.jpg
, this means "start at the "base directory, go back one, go back one, go back one, go into img/, find file". So the "base directory" needs to be ahead of the the files to take accound for the fact you're going back.Working example:
/home/john/projects/proj/public/img/image.jpeg
../../../img/image.jpeg
/home/john/projects/proj/public/a/b/c/
/home/john/projects/proj/public/a/b/c/../../../img/image.jpeg
/home/john/projects/proj/public/a/b/../../img/image.jpeg
/home/john/projects/proj/public/a/../img/image.jpeg
/home/john/projects/proj/public/img/image.jpeg
= Bingo.If this doesn't work, adjust your setBaseDirectory until you get the right path.