我尝试使用带有自定义页眉和页脚的WhiteOctoberTCPDFBundle在Symfony中生成pdf。
即使在生成缓存时,我总是会收到以下错误:
[语义错误]注释" @ class"在类中,从未导入过TCPDF。您是否忘记添加"使用"这个注释的陈述?
就像Doctrine注释阅读器试图将@class解释为与ORM注释相关的东西。知道怎么解决吗?
在我的config.yml
中white_october_tcpdf:
class: 'Acme\DemoBundle\Pdf\MyClass'
在我的自定义类中:
namespace Acme\DemoBundle\Pdf
use JMS\DiExtraBundle\Annotation as DI;
use TCPDF;
/**
*
* @DI\Service("foo.pdf_test")
*/
class MyClass extends TCPDF
{
public function Header()
{
// some content
}
public function Footer()
{
// some content
}
}
在我的控制器中:
/**
* @MVC\Route("/pdf", name="pdf")
* @MVC\Template()
*
* @return Response
*/
public function pdfAction()
{
$pdf = $this->container->get("white_october.tcpdf")->create();
$pdf->AddPage();
// some content
$response = new Response($pdf->Output('test.pdf', 'I'));
$response->headers->set('Content-Type', 'application/pdf');
return $response;
}
编辑:
@class代码(在供应商中)
/**
* @class TCPDF
* PHP class for generating PDF documents without requiring external extensions.
* TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
* @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions.
* @version 6.2.0
* @author Nicola Asuni - info@tecnick.com
*/
class TCPDF {
// ....
}
答案 0 :(得分:0)
您可以通过全局排除注释来解决此问题。
AnnotationReader::addGlobalIgnoredName("class");