drzk21632 2013-09-04 20:41
浏览 48
已采纳

phpdocx generatePDF未知图像类型:?image = opentbs1

First of all, this is my first question on the site and I just want to thank all of you for helping out newbs like me. I have found so much invaluable information on this site! It has helped me with so much along my programming journey.

So here is my question. I have used OpenTBS (PHP class) to fill a .docx template with dynamic data and to insert an image in the document.

The image is inserted by entering the following command into the alternate text of the image:

[onshow.logo_location;ope=changepic;tagpos=inside;adjust=100%;]

I have a variable that I have set as $logo_location that points to the image that is to be inserted.

This step works perfectly. A docx file is created with the appropriate image in the right location.

When I try to convert this docx file to a PDF using phpdocx I get an error. The code to generate the pdf is the following:

require_once '../bbms/classes/phpdocx/classes/TransformDoc.inc';
require_once '../bbms/classes/phpdocx/classes/CreateDocx.inc';

$docx = new CreateDocx();

$document = new TransformDoc();
$document->setStrFile('199.docx');
$document->generatePDF();

The error I get is the following:

Unable to generate PDF file. exception 'DOMPDF_Exception' with message 'Unknown image type: ?image=opentbs1.' in C:\wamp\www\bbms\classes\phpdocx\pdf\include\image_cache.cls.php:188 Stack trace: #0 C:\wamp\www\bbms\classes\phpdocx\pdf\include\image_frame_decorator.cls.php(88): Image_Cache::resolve_url('?image=opentbs1', NULL, '', '') #1 C:\wamp\www\bbms\classes\phpdocx\pdf\include\frame_factory.cls.php(199): Image_Frame_Decorator->__construct(Object(Frame), Object(DOMPDF)) #2 C:\wamp\www\bbms\classes\phpdocx\pdf\include\dompdf.cls.php(606): Frame_Factory::decorate_frame(Object(Frame), Object(DOMPDF)) #3 C:\wamp\www\bbms\classes\phpdocx\classes\TransformDoc.inc(328): DOMPDF->render() #4 C:\wamp\www\discount_database\test.php(23): TransformDoc->generatePDF() #5 {main}

For some reason, the location for the new image in the docx file is being passed as "?image=opentbs1." to the static function resolve_url() in image_cache.cls.php.

When I tried to convert a normal docx file that wasn't created using OpenTBS, I didn't get this error. I checked what a valid url being sent to resolve_url() would look like and it looks like this:

"files/files_invoice_template.docx/media/word/media/image1.png"

Is there a way to configure openTBS to correctly set an inserted image's url / location?

Thank you!!

  • 写回答

1条回答 默认 最新

  • douli8428 2013-09-04 21:36
    关注

    I don't use PHPDOCX or make PDFs from my OpenTBS stuff, but it looks like PHPDOCX has hardcoded the relationship name into their image recognition. Just looking at the code on github, it looks like if you change line 239 in phpDocx/classes/TransformDoc.inc.php:

        foreach ($domImgs[0] as $dats) {
            $datsFiltered = explode('"', $dats);
            if (preg_match('/^\?image=rId/', $datsFiltered[1])) { // <--this is line 239
                $datFiltered = explode('?image=', $dats);
                $idImgs[] = substr($datFiltered[1], 0, -1);
            }
        }
    

    to something like

    if (preg_match('/^\?image=(rId|opentbs)/', $datsFiltered[1])) { // <--this is line 239
    

    Since all images switched in by OpenTBS use opentbs as a prefix to avoid conflicts with existing elements.

    I'm no regular expression expert, so lets call this pseudo code. Hope it points you in the right direction at least.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝