未找到图像或未知类型(使用带有dompdf的tinymce来显示以pdf格式存储在tinymce textarea中的html) [英] Image not found or type unknown (using tinymce with dompdf to show html stored in tinymce textarea in a pdf)

查看:333
本文介绍了未找到图像或未知类型(使用带有dompdf的tinymce来显示以pdf格式存储在tinymce textarea中的html)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel-tinymce-simple-imageupload软件包上传图片。当用户在textarea中输入一些内容并单击表单提交按钮时,我想将内容放在textarea中的pdf文件中。我有以下代码。

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.

问题是在pdf文件中,如果在textarea中插入图像,则图像不会出现在pdf中pdf显示图片未找到或输入未知。

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>

获取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代码的relative_urls为false:

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();
    }
});

我已经使用setOptions(['isHtml5ParserEnabled'=> true,'isRemoteEnabled'=> true] )但也不适用于它,它显示相同的错误。

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

似乎问题可能是因为需要更改图像的url路径。但我不明白如何做到这一点,因为用户只选择tinymce textarea中的图像如何更改该图像的绝对路径。

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.

推荐答案

这是一个报道的问题: https://github.com/dompdf/dompdf / issues / 1659

This is a reported issue: https://github.com/dompdf/dompdf/issues/1659 .

建议你:


  1. 设置relative_urls为true(这会将图像设置为 img / image_15zdbBr.jpeg

  2. 设置 $ dompdf - > setBasePath($ base_path)其中$ base_path是文件所在的位置。( https://github.com/dompdf/dompdf/wiki/Usage#setbasepath

  1. set relative_urls to true (this will set the image as img/image_15zdbBr.jpeg, and
  2. set $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:


  1. 当您使用Laravel的包装器时,您需要获得domPDF类的句柄将通过 $ pdf-> ge完成tDomPDF() - > setBasePath();

  2. 由于相对文件路径为 ../../../ image /file.jpg ,这意味着从基础目录开始,返回一个,返回一个,返回一个,进入img /,找到文件。因此,基础目录需要先于文件,以便为您回去的事实做好准备。

  1. As you are using a wrapper for Laravel, You need to get a handle on the domPDF class which you will do through $pdf->getDomPDF()->setBasePath();
  2. As the relative file path is ../../../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.

工作示例:


  • 您的实际文件位于 / home / john / projects / proj / public中/img/image.jpeg

  • 相对文件路径(已提供)= ../../../ img / image。 jpeg

  • 所以你配置你的setBasedirectory = / 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。

  • Your actual file is located (for real) in /home/john/projects/proj/public/img/image.jpeg
  • Relative file path (provided) = ../../../img/image.jpeg
  • So you configure your setBasedirectory = /home/john/projects/proj/public/a/b/c/
  • Combined this gives you /home/john/projects/proj/public/a/b/c/../../../img/image.jpeg
  • Which is the same as /home/john/projects/proj/public/a/b/../../img/image.jpeg
  • Which is the same as /home/john/projects/proj/public/a/../img/image.jpeg
  • Which is the same as /home/john/projects/proj/public/img/image.jpeg = Bingo.

如果这不起作用,请调整setBaseDirectory直到你得到了正确的道路。

If this doesn't work, adjust your setBaseDirectory until you get the right path.

这篇关于未找到图像或未知类型(使用带有dompdf的tinymce来显示以pdf格式存储在tinymce textarea中的html)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆