"对象的错误引用"或"消息:概述子项加载错误。"

时间:2014-08-13 19:09:31

标签: php pdf zend-framework zend-framework2 zend-pdf

该程序正在使用Zend_Pdf创建PDF附件并加载pdf文件。我知道Zend_Pdf只能用于等于或低于1.4版本的PDF文件。

所有文件均为1.3版本。创建并正确附加了五个pdf附件,但是一个文件在加载时产生错误。我不确定是什么原因以及如何解决它:

错误1:文件降级为1.3版

An error occurred

Application error

Exception information:

Message: Outline childs load error.

Stack trace:

#0 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#1 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#2 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#3 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#4 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#5 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#6 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#7 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#8 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(549): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference))
#9 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(317): Zend_Pdf->_loadOutlines(Object(Zend_Pdf_Element_Reference))
#10 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(253): Zend_Pdf->__construct('C:\WebSites\Web...', NULL, true)
#11 C:\WebSites\Web_Applications\workstudy\application\modules\default\models\Students.php(609): Zend_Pdf::load('C:\WebSites\Web...')
#12 C:\WebSites\Web_Applications\workstudy\application\modules\default\controllers\StudentsController.php(262): Model_Students->generateDocuments()
#13 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Action.php(513): StudentsController->quizCompletedAction()
#14 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('quizCompletedAc...')
#15 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#16 C:\WebSites\Web_Applications\workstudy\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#17 C:\WebSites\Web_Applications\workstudy\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#18 C:\WebSites\RSS\Workstudy\index.php(26): Zend_Application->run()

**错误2:当文件未正确降级到较低版本**

时,可能会发生错误
An error occurred

Application error

Exception information:

Message: Incorrect reference to the object

Stack trace:

#0 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Element\Reference.php(128): Zend_Pdf_Element_Reference->_dereference()
#1 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(529): Zend_Pdf_Element_Reference->getType()
#2 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(317): Zend_Pdf->_loadOutlines(Object(Zend_Pdf_Element_Reference))
#3 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(253): Zend_Pdf->__construct('C:\WebSites\Web...', NULL, true)
#4 C:\WebSites\Web_Applications\workstudy\application\modules\default\models\Students.php(597): Zend_Pdf::load('C:\WebSites\Web...')
#5 C:\WebSites\Web_Applications\workstudy\application\modules\default\controllers\StudentsController.php(262): Model_Students->generateDocuments()
#6 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Action.php(513): StudentsController->quizCompletedAction()
#7 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('quizCompletedAc...')
#8 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 C:\WebSites\Web_Applications\workstudy\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 C:\WebSites\Web_Applications\workstudy\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 C:\WebSites\RSS\Workstudy\index.php(26): Zend_Application->run()
#12 {main}  

Php代码:

...

$mail = new Zend_Mail();
$mail->setFrom(Zend_Registry::get('config')->app->contact->email);
$mail->addTo($this->getUscEmail(), $this->getFirstName().' '.$this->getLastName());
$mail->addCc(Zend_Registry::get('config')->app->contact->email, 'SOWK FWS');
$mail->setSubject('Workstudy Documentation - '.$this->getFirstName().' '.$this->getLastName());
$content = '......text......';

$mail->setBodyText(strip_tags($content));
$mail->setBodyHtml($content);


...

$file = Zend_Registry::get('config')->app->pdf_path."Foundation Year Students.pdf"; //load pdf from string
$pdf = Zend_Pdf::load($file);
$at1 = $mail->createAttachment($pdf->render());
$at1->filename = "Foundation Year Students steve.pdf";
$at1->type        = 'application/pdf';

...

1 个答案:

答案 0 :(得分:0)

附加同一文件的另一种方法解决了问题:

    $file = Zend_Registry::get('config')->app->pdf_path."Foundation Year Students-Instructions.pdf"; //load pdf from string
            $content = file_get_contents($file); // e.g. ("attachment/abc.pdf")
    $attachment = new Zend_Mime_Part($content);
    $attachment->type = 'application/pdf';
    $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
    $attachment->encoding = Zend_Mime::ENCODING_BASE64;
    $attachment->filename = 'Foundation Year Students-Instructions.pdf'; // name of file

    $mail->addAttachment($attachment);