Wednesday, 25 July 2018

integrate Tinymce with dompdf

Im using tinymce with image upload using the package "laravel-tinymce-simple-imageupload". So I have a page where the user can select a registration type and enter some content in the tinymce textarea to associated that content to the selected registration type.

In the textarea the user can also upload images using the tinymce-simple-image-upload and this images are stored in "~/projects/proj/public/img/image_15....".

The content is stored in database in the certificates table in the column "content" like:

<p>certificate test<img src="../../../img/image_1532441196_7GTrIzUnb.jpeg" 
   alt="" width="1200" height="900" /></p>

Error: The issue is that I have the code below to get a pdf with the certificate content associated with a specific registration and it works. But the downloaded pdf file, if the certifiate content has an image, the image dont appear in the pdf, in the pdf instead of show the image show this error "Image not found or type unknown".

Do you know why?

Code to get the certificate HTML from db in pdf:

public function getCertificateInfo($regID)
    {

        $participants = Participant::where('registration_id', $regID)
            ->whereHas('registration_type', function ($query) {
                $query->where('certificate_available', 'Y');
            })
            ->with('registration_type.certificate')
            ->get();

        $content = '';
        foreach ($participants as $participant) {
          $content .=
          '<div style="page-break-inside: avoid; page-break-after: always;">
                  '.$participant->registration_type->certificate->content.'</div>';
        }

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

        $pdf->getDomPDF()->setBasePath(public_path().'/../../');

        $pdf->loadHTML($content);

        return $pdf->download('certificates.pdf');

    }

TinyMce code:

tinymce.init({
          selector:'textarea',
          plugins: 'image code link',
          relative_urls: true,

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

Like this with the html static it works, the image appears:

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


   $pdf->loadHTML('<p>cert1<img src="'.public_path().'/img/image_1532441196_7GT.jpeg" alt="" width="1200" height="900" /></p>');


 return $pdf->download('certificates.pdf');

The $content variable shows like:

"""
<div style="page-break-inside: avoid; page-break-after: always;">\n
    <p>cert1<img src="../../../img/image_1532441196_7GT.jpeg" 
    alt="" width="1200" height="900" /></p></div> ▶
</div>
"""



from integrate Tinymce with dompdf

No comments:

Post a Comment