将图像包含在数组中

问题描述:

the following code works great for adding a nice header and footer to a pdf output, but i'm trying to add an image to the header and footer instead of just page numbers, etc. How would i go about this? Thanks.

$pdf_header = array (
    'odd' => 
        array (
            'R' => 
                array (
                    'content' => '{PAGENO}',
                    'font-size' => 8,
                    'font-style' => 'B',
                    'font-family' => 'DejaVuSansCondensed',
                ),
                'line' => 1,
            ),
    'even' => 
        array (
            'R' => 
                array (
                    'content' => '{PAGENO}',
                    'font-size' => 8,
                    'font-style' => 'B',
                    'font-family' => 'DejaVuSansCondensed',
                ),
                'line' => 1,
        ),
    );
    $pdf_footer = array (
    'odd' => 
        array (
            'R' => 
                array (
                    'content' => '{DATE d.m.Y}',
                    'font-size' => 8,
                    'font-style' => 'BI',
                    'font-family' => 'DejaVuSansCondensed',
                ),
            'C' => 
                array (
                    'content' => '- {PAGENO} / {nb} -',
                    'font-size' => 8,
                    'font-style' => '',
                    'font-family' => '',
                ),
            'L' => 
                array (
                    'content' => get_bloginfo('name'),
                    'font-size' => 8,
                    'font-style' => 'BI',
                    'font-family' => 'DejaVuSansCondensed',
                ),
            'line' => 1,
        ),
    'even' => 
        array (
            'R' => 
                array (
                    'content' => '{DATE d.m.Y}',
                    'font-size' => 8,
                    'font-style' => 'BI',
                    'font-family' => 'DejaVuSansCondensed',
                ),
            'C' => 
                array (
                    'content' => '- {PAGENO} / {nb} -',
                    'font-size' => 8,
                    'font-style' => '',
                    'font-family' => '',
                ),
            'L' => 
                array (
                    'content' => get_bloginfo('name'),
                    'font-size' => 8,
                    'font-style' => 'BI',
                    'font-family' => 'DejaVuSansCondensed',
                ),
            'line' => 1,
        ),
    );

So, in your multi-dimensional arrays it looks like you're storing the CSS property along with its value. Are you looking for something like '#certainImage' => 'background: url(\'imgname.ext\')'? Also I might suggest, instead of doing alternating 'even' and 'odd' try making a flip flop statement with a ternary operator. I've done something in the past like $oddeven['R'][] = isset($var) ? 'odd' : 'even'; . That way you can simply step through the iterated array and change the value of each element without having to type 'even' or 'odd' repeatedly. It'll save you time.