FPDF - WriteHTML in Multicell?

前端 未结 6 1136
情书的邮戳
情书的邮戳 2021-01-03 13:12

Can WriteHTML placed in Multicell? How?

I retrieved and display the HTML output from database but want to position it in the 2nd column(let\'s say) so I put it in Mu

6条回答
  •  粉色の甜心
    2021-01-03 13:47

    I found that using writeHTML in multicell to be not the right solution. Multicell needs to know how to set the style for the tags. WriteHTML can't do the job because it's setting style information as it interprets the tagged entities, which will do nothing by the time the original multicell function is called.

    I found a method that works: use class.multicelltag.php from https://github.com/marxjohnson/moodle-local_progressreview/blob/master/fpdf/class.multicelltag.php

    Note: class.multicelltag is licensed under gnu license, free for non-commercial usage. If you need a commercial license, see http://www.interpid.eu/fpdf-components

    If you use it with another fpdf extention (such as PDF_Label), here's an example:

    require_once("class.multicelltag.php"); 
    // note: you will also need class.string_tags.php for an include to class.multicelltag.php
    // note: class.multicelltag.php already includes fpdf.php
    class PDF_Label extends FPDF_MULTICELLTAG {
        ...
        // define what the tag will do with style information for the font family
        // this defines bold html tag to use current font, "B" style, current character size incremented by 1, and black for the color
        $this->SetStyle2('b',$this->_Font_Name,"B",$this->_Char_Size+1,"0,0,0");
    
        function Add_PDF_Label($texte,$align,$border,$imageFile='',$imageWidth=0,$imageHeight=0) {
            ...
            $this->ext_MultiCellTag($this->_Width, $this->_Line_Height, $texte,$border,$align,$fill);
    
        }
    }
    

    I noticed that the class.multicelltag.php function ApplyStyle tries to use the DejaVu fonts which are not part of fpdf's core font's, so I changed this to use helvetica.

提交回复
热议问题