Zend PDF 保存和渲染文件的不同字体大小

发布于 2024-10-06 08:09:57 字数 1424 浏览 3 评论 0原文

我尝试打开一个现有文件,通过包含文本对其进行修改,然后将其发送给用户(渲染)。我认识到字体大小仅针对文件的保存版本而改变。如果我只渲染它,字体大小将被忽略。

为什么会发生这种情况?我做错了什么?我可以做点什么来反对它吗?

您好,
-洛尼

    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    // fetch allready styled pdf
    $pdf = Zend_Pdf::load('img/voucher/gift_vouchers.pdf');

    // set default color and font with size
    $style = new Zend_Pdf_Style();
    $style->setFillColor(new Zend_Pdf_Color_Html('#c34827'));
    $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 9);

    // fetch first page
    $page = $pdf->pages[0];

    // set default style to page
    $page->setStyle($style);

    $page->drawText('To_', 72, 10);
    $page->drawText('From_', 72, 200);
    $page->drawText('For_Chrismas', 1, 100);
    $page->drawText('For_Message Lorem Ipsum isries.', 72, 520);
    $page->drawText('1231233123', 72, 520);
    $page->drawText('23/12/2010', 72, 520);

    // only for DEBUG to show difference
    $pdf->save('img/voucher/voucher-'.Zend_date::now()->getTimestamp().'.pdf');

    $this->getResponse()->setHeader('Content-type', 'application/pdf', true);
    $this->getResponse()->setHeader('Content-disposition', 'inline; filename=' . $this->_pdfName . '.pdf', true);
    $this->getResponse()->setBody($pdf->render(false));

I tryed to open an existing file modify it by including text and then send it to the user (render). What I recognised is that the font size only changes for the saved version of the file. If I only render it, the font size is ignored.

Why is this happening? What do I do wrong? Can I do something against it?

Greetings,
-lony

    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    // fetch allready styled pdf
    $pdf = Zend_Pdf::load('img/voucher/gift_vouchers.pdf');

    // set default color and font with size
    $style = new Zend_Pdf_Style();
    $style->setFillColor(new Zend_Pdf_Color_Html('#c34827'));
    $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 9);

    // fetch first page
    $page = $pdf->pages[0];

    // set default style to page
    $page->setStyle($style);

    $page->drawText('To_', 72, 10);
    $page->drawText('From_', 72, 200);
    $page->drawText('For_Chrismas', 1, 100);
    $page->drawText('For_Message Lorem Ipsum isries.', 72, 520);
    $page->drawText('1231233123', 72, 520);
    $page->drawText('23/12/2010', 72, 520);

    // only for DEBUG to show difference
    $pdf->save('img/voucher/voucher-'.Zend_date::now()->getTimestamp().'.pdf');

    $this->getResponse()->setHeader('Content-type', 'application/pdf', true);
    $this->getResponse()->setHeader('Content-disposition', 'inline; filename=' . $this->_pdfName . '.pdf', true);
    $this->getResponse()->setBody($pdf->render(false));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文