Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adamjhn's avatar

Get tinymce content in a pdf using dompdf: Image not found or type unknown

Im using tinymce with image upload using the package "laravel-tinymce-simple-imageupload". But when the user enters some content in the textarea and click in the form submit button I want to put the content in the textarea in a pdf file so I have the code below.

The issue is that in the pdf file, if is inserted an image in the textarea, the image dont appear in the pdf and it shows "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_1530423144_Yn4tAJwZmzcbb82UOGHo07eIQsiGfzdbBjh10r.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('invoice.pdf');

0 likes
12 replies
adamjhn's avatar

It seems that is necessary to change the url path of the image to solve the issue, but using tinymce, is only necessary to click in the browse image button and selet an image, so I dont understand how to change the url path of the image?

adamjhn's avatar

Thanks, but I already use "setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])" but also dont works with that, it show the same error.

Then as I said in the quetion, 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 chnge the absolute path of that image.

Cronix's avatar

Save it on your server first. Then access it.

Edit: there is a lot of info in those threads. You didn't try all of them...

adamjhn's avatar

But the image is already stored in the server, with the question code the $certificate->content has the content that can have or not images, the issue is when it has images, like:

<p>test content<img src="/img/image_100.jpeg" width="1200" height="900" /></p>

question code:

 //get the certificate associated with the regitration type
   $certificateContent = RegistrationType::with('certificate')->where('id', $request->registrationType)->first();

    $pdf = app()->make('dompdf.wrapper');

    // load a HTML in the pdf
    $pdf->loadHTML($certificateContent->certificate->content);

   // dowload pdf
    return $pdf->download('invoice.pdf');
Cronix's avatar

Yes, they also suggest to use full url with domain name, remove first slash, etc, and other things. Try everything they suggest, not just some things.

Did you try those? no...

adamjhn's avatar

But its that part that Im not understanding. It seems that to solve the issue is necessary to use the full url. But the user in the textarea clicks in the upload image button, selects a image and then click in the form submit button and the content of the textrea is stored in the database. But how to change this url of the image

 "<p>test content<img src="/img/image_100.jpeg" width="1200" height="900" /></p>" 

to the full url? Because that image is inserted by the tinymce plugin no?

Cronix's avatar

But how to change this url of the image to the full url? Because that image is inserted by the tinymce plugin no?

Have you read through the tinymce docs? Your answer is in there. Look at configuration options.

adamjhn's avatar

Thanks, but here "https://www.tiny.cloud/docs/configure/url-handling/"says "If this option is set to true, all URLs returned from the MCFileManager will be relative from the specified document_base_url. If it's set to false all URLs will be converted to absolute URLs." but Im already using " relative_urls: false, " but dont works.

Cronix's avatar
relative_urls : false,
document_base_url : "http://www.example.com/"

And you set the base url?

adamjhn's avatar

yes, its like this:

 tinymce.init({
                    selector:'textarea',
                    plugins: 'image code link',
                    relative_urls: false,
                    document_base_url : "https://proj.test/img/",

                    file_browser_callback: function(field_name, url, type, win) {
                        // trigger file upload form
                        if (type == 'image') $('#formUpload input').click();
                    }
                });

Cronix's avatar

Ok. Could be several things. Could be the dompdf package, or tinymce, or the combination of both. I really don't know what else to tell you. I don't want to set all of this to test it. I'd start by searching in the dompdf issues on github, and asking there if you don't find a solution. If you make an issue, be sure to include all relevant info so they don't have to ask you a million questions on how you set everything up.

1 like

Please or to participate in this conversation.