doumu6941 2016-08-05 01:14
浏览 76

在dompdf中,相对于“setBasePath”函数是什么?

I am rendering some html pages in dompdf. But It doesn't seem to be able to include my images or external css files. If I simply print the page to the screen everything works fine. But dompdf can't find them.

I found a function called: setBasePath where the documentation states "Sets the base path used for external stylesheets and images." Sound like what I want but what is this base path relative too? I tried entering relative to root but it still doesn't find anything.

$dompdf = new Dompdf();
$dompdf->loadHtml($template);
$dompdf->setBasePath(realpath('./'));
$dompdf->render();
$dompdf->stream('note');
  • 写回答

1条回答 默认 最新

  • douniewei6346 2016-08-08 17:11
    关注

    The base path is the path used when a resource is references using a relative path (e.g. inc/site.css). For resources referenced using absolute paths or full URIs the base path would not be used.

    As with any other running script Dompdf doesn't have knowledge of any root path other than the file system root. Thus, any absolute path is read from the root of the file system. Relative paths are determined based on the current working directory (CWD) of the executing PHP script.

    In your example you set the base path relative to ./ which would be the same as the base path already used by dompdf when loading a document using $dompdf->loadHtml(). To give a more complete answer it would help to have more information on your file layout and how you reference those files in the HTML.

    Try this discussion for more information on how resource references are interpreted.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大