问题描述
我需要在 pdf 文档中显示图像,但我的图像存储在公共文件夹之外。
我做了一个特定的动作来显示我的图像,它在前面工作正常,但我无法在我的 pdf 中显示我的图像。
我的行动:
/**
* @Route("/get_file/{uuid}",name="bo_client_header_get_file",methods={"GET"})
* @param $uuid
* @return Response|NotFoundHttpException
*/
public function getHeaderFile($uuid)
{
$uuid = Uuid::fromString($uuid);
$header = $this->getDoctrine()->getManager()->getRepository(Header::class)->findOneByUuid($uuid);
if ($header) {
$file = $this->projectDir . DIRECTORY_SEParaTOR . $this->documentsDir . $header->getFilepath();
if (!file_exists($file)) {
$file = $this->projectDir . DIRECTORY_SEParaTOR . 'public' . $header->getFilepath();
}
if (!file_exists($file)) {
$file = $this->projectDir . $header->getFilepath();
}
if (file_exists($file)) {
$response = new Response();
$response->headers->set('Content-Type',mime_content_type($file));
$response->setContent(file_get_contents($file));
return $response;
}
}
return new NotFoundHttpException('Header inexistant');
}
我的 html(树枝模板):
{{ url('bo_client_header_get_file',{client: announce.header.client.id,uuid: announce.header.uuid}) }}
<div class="hg-headercard">
<img class="announceHeaderimg"
height="{{ announce.header.size }}" src="{{ url('bo_client_header_get_file',uuid: announce.header.uuid}) }}"/>
第一个 url() 用于调试目的。打印在我的 pdf 上的 url 是有效的,如果我将其粘贴到浏览器中,则会显示我的图像,所以我担心我的问题出在某些特定的 wkhtmltopdf 设置上。 也许我的控制器中缺少一些响应标头。
我正在使用 symfony 5.3、wkhtmltopdf 0.12.6 和修补过的 qt
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)