4

symfony プロジェクトで WhiteOctober TCPDF バンドルの使用を開始しましたが、ページ形式などのデフォルトの構成値を変更する方法がわかりません。私はconfig.ymlにそれを入れてみました:

white_october_tcpdf:
    tcpdf:
        k_tcpdf_external_config: true
        pdf_page_format: 'LETTER'
        pdf_author: 'Company Name'
        pdf_header_title: 'Order Confirmation'
        pdf_header_string: 'Company Name'
        pdf_header_logo: '%kernel.root_dir%/../web/images/logo.png'
        pdf_header_logo_width: '35'
        pdf_margin_header: 15
        pdf_margin_footer: 15
        pdf_margin_top: 25
        pdf_margin_bottom: 25
        pdf_margin_left: 25
        pdf_margin_right: 25

しかし、呼び出し時には完全に無視されます

$pdf = $this->get('white_october.tcpdf')->create();

私のコントローラーで。生成された PDF は A4 のままで、ヘッダーとデフォルトの余白はありません。

バンドルにカスタム構成を適用させるために何か不足していますか?

4

5 に答える 5

1

私も同じ問題を抱えてる。ベンダー コードの変更はベスト プラクティスではありません。私の回避策は次のとおりです。

src フォルダーに新しいクラス「CustomWhiteOctoberTCPFBundle」を作成しました。

namespace TCPDFBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class CustomWhiteOctoberTCPDFBundle extends Bundle
{
 public function getParent()
    {
        return 'WhiteOctoberTCPDFBundle';
    }  
    public function boot() {
         //Put modified method as mentioned in the previous answer

    }
}

On AppKernel.php put:
    public function registerBundles()
    {
        $bundles = array(...
            new WhiteOctober\TCPDFBundle\WhiteOctoberTCPDFBundle(),
            new TCPDFBundle\CustomWhiteOctoberTCPDFBundle(),
于 2015-07-29T14:55:39.350 に答える
0

このコードを追加...

            if (preg_match("/^pdf_/i", $k)) {
                if (!defined($constKey)) {
                    define($constKey, $v);
                }
            }

バンドルファイルに

 /vendor/whiteoctober/tcpdf-bundle/WhiteOctober/TCPDFBundle/WhiteOctoberTCPDFBundle.php

元のファイルhttps://github.com/wrep/TCPFBundle/blob/master/WrepTCPFBundle.php は現在、で始まる構成パラメーターのみに一致し^k ます このバンドルの構成オプションはここに表示されます

https://github.com/wrep/TCPDFBundle/blob/master/WrepTCPDFBundle.php

上記のドキュメントの構成例には記載されていない tcpdf_config.php からさらにいくつかの構成パラメーターを追加する必要がありました。ここに私の完全な white_october_tcpdf: セクションがありますapp/config/config.yml

...ober_tcpdf:
file:                 %kernel.root_dir%/../vendor/tecnick.com/tcpdf/tcpdf.php
class:                TCPDF
tcpdf:
    k_path_url:           %kernel.root_dir%/../vendor/tecnick.com/tcpdf/
    k_path_main:          %kernel.root_dir%/../vendor/tecnick.com/tcpdf/
    k_path_fonts:         %kernel.root_dir%/../vendor/tecnick.com/tcpdf/fonts/
    k_path_cache:         %kernel.cache_dir%/tcpdf
    k_path_url_cache:     %kernel.cache_dir%/tcpdf
    k_path_images:        %kernel.root_dir%/../vendor/tecnick.com/tcpdf/examples/images/
    k_blank_image:        %kernel.root_dir%/../vendor/tecnick.com/tcpdf/examples/images/_blank.png
    k_cell_height_ratio:  1.25
    k_title_magnification:  1.3
    k_small_ratio:        0.66666666666667
    k_thai_topchars:      true
    k_tcpdf_calls_in_html:  true
    k_tcpdf_external_config:  true
    head_magnification:   10
    pdf_page_format:      LETTER
    pdf_page_orientation:  P
    pdf_creator:          TCPDF
    pdf_author:           TCPDF
    pdf_header_title:  Example Title
    pdf_header_string: "this is motto - My Company\nwww.mycompany.org" 
    pdf_header_logo: ../../../../../web/bundles/home/images/peas.jpg    
    pdf_header_logo_width: 30
    pdf_unit:             mm
    pdf_margin_header:    5
    pdf_margin_footer:    10
    pdf_margin_top:       27
    pdf_margin_bottom:    25
    pdf_margin_left:      15
    pdf_margin_right:     15
    pdf_font_name_main:   helvetica
    pdf_font_size_main:   10
    pdf_font_name_data:   helvetica
    pdf_font_size_data:   8
    pdf_font_monospaced:  courier
    pdf_image_scale_ratio:  1.25
于 2014-03-20T03:30:05.293 に答える
0

さて、今私は同じ問題を解決しました:

ミルクが言ったように、必要な定数を定義する必要があります。

white_october_tcpdf:
tcpdf:
  .
  .
  .

次に、クラスを変更する必要があります: /vendor/whiteoctober/tcpdf-bundle/WhiteOctober/TCPDFBundle/WhiteOctoberTCPDFBundle.php このコードで

                // All K_ and _pdf constants are required
            if (preg_match("/^k_/i", $k) OR preg_match("/^pdf_/i", $k)) {
                if (!defined($constKey)) {
                    $value = $this->container->getParameterBag()->resolveValue($v);
                    if (($k === 'k_path_cache' || $k === 'k_path_url_cache') && !is_dir($value)) {
                        $this->createDir($value);
                    }

                    define($constKey, $value);
                }
            }

両方の定数タイプに一致します。

于 2016-10-18T06:55:57.903 に答える
0

vendor/tecnick.com/tcpdf/config フォルダーにある tcpdf_config.php を編集する必要があります。

于 2014-03-17T19:23:12.353 に答える