用writeHTML里面的中文乱码,用write的话html页面只显示页面代码但是中文没有问题

解决方案 »

  1.   

    $pdf->SetFont(‘stsongstdlight’, ”, 20);
      

  2.   

    早就试了,这个不行,用writerHTML函数不好使
      

  3.   

    tcpdf 要求中文内容是 utf-8 编码的,而显然你的是 gbk 的帖出乱码的截图是很有必要的,因为他有助于问题的判断,因为乱码的评定标准因人而异如果你不说 中文在文件中都是问号,我也无法做出判断,而 问号 并不是乱码
      

  4.   

    function pdf($html,$paper_number){
        $filename = time();
        vendor('Tcpdf.tcpdf');
        $pdf = new \Tcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // 设置打印模式
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('boshuo');
        $pdf->SetTitle('BOSHUO');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // 是否显示页眉
        $pdf->setPrintHeader(false);
        // 设置页眉显示的内容
        // $pdf->SetHeaderData('logo.png', 60, 'boshuo.org', '博硕论文', array(0,64,255), array(0,64,128));
        // 设置页眉字体
        // $pdf->setHeaderFont(Array('dejavusans', '', '0'));
        // 页眉距离顶部的距离
        // $pdf->SetHeaderMargin('0');
        // 是否显示页脚
        $pdf->setPrintFooter(false);
        // 设置页脚显示的内容
        // $pdf->setFooterData(array(0,64,0), array(0,64,128));
        // 设置页脚的字体
        // $pdf->setFooterFont(Array('dejavusans', '', '0'));
        // 设置页脚距离底部的距离
        // $pdf->SetFooterMargin('0');
        // 设置默认等宽字体
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // 设置行高
        $pdf->setCellHeightRatio(1);
        // 设置左、上、右的间距
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP,PDF_MARGIN_RIGHT);
        $pdf->setCellPaddings(0, 0, 0, 0);
        // 设置是否自动分页  距离底部多少距离时分页
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        // 设置图像比例因子
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
            require_once(dirname(__FILE__).'/lang/eng.php');
            $pdf->setLanguageArray($l);
        }
        $pdf->setFontSubsetting(true);
        $pdf->AddPage();
        // $pdf->AddPage("A4","Landscape",true,true);
        // 设置字体
        $pdf->SetFont('stsongstdlight', '', 14, '', true);    $pdf->writeHTML($html, true, false, false, false, '');//HTML生成PDF
        // $pdf->Write(0,$html,'', 0, 'L', true, 0, false, false, 0);
        $pdf->writeHTMLCell();
        ob_clean();
        $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
    $showType= 'F';//PDF输出的方式。I,在浏览器中打开;D,以文件形式下载;F,保存到服务器中;S,以字符串形式输出;E:以邮件的附件输出。
      return $pdf->Output($_SERVER["DOCUMENT_ROOT"].'/Upload/pdf/'.$paper_number.'.pdf', $showType);
    } public function pdf(){
            $a= '1547685188';
            $time = date('d-m-Y',$a);
            $writer = '俊 莫 and 春梅 毛';
            $paper_number= '录用通知';
            $title='基于业缘资本理论的高职“三库一体”式创业师资人才库建设探究';
            // p($title);
            // p($writer);die;
            $html = '
              <!DOCTYPE><html><head><meta charset="utf-8"><title>录用通知</title><style type="text/css">*{margin:0;padding:0;text-indent:0}h1{color:black;font-family:"Century Gothic",sans-serif;font-style:normal;font-weight:bold;text-decoration:none;font-size:16pt}.h2,h2{color:#974705;sans-serif;font-style:normal;font-weight:bold;text-decoration:none;font-size:10.5pt}.s1{color:black;font-family:"Century Gothic",sans-serif;font-style:normal;font-weight:normal;text-decoration:none;font-size:10.5pt}.s2{color:black;sans-serif;font-style:normal;font-weight:bold;text-decoration:none;font-size:10.5pt}.s4{color:black;font-family:"Century Gothic",sans-serif;font-style:normal;font-weight:normal;text-decoration:none;font-size:7pt;vertical-align:2pt}p{color:black;font-family:"Century Gothic",sans-serif;font-style:normal;font-weight:normal;text-decoration:none;font-size:8pt;margin:0pt}.h3{color:black;font-family:Calibri,sans-serif;font-style:normal;font-weight:bold;text-decoration:none;font-size:8pt}.s5{color:black;font-family:"Century Gothic",sans-serif;font-style:italic;font-weight:normal;text-decoration:none;font-size:8pt}.s6{color:black;font-family:"Century Gothic",sans-serif;font-style:italic;font-weight:normal;text-decoration:none;font-size:5pt;vertical-align:2pt}</style></head><body><h1 style="padding-top: 3pt;padding-left: 152pt;text-indent: 0pt;text-align: left;">Acceptance Letter</h1><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-top: 5pt;text-indent: 0pt;text-align: right;">Date:'.$time.'</h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s1"style="padding-top: 5pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Dear<span class="h2">'.$writer.'</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s2"style="padding-top: 9pt;padding-left: 5pt;text-indent: 0pt;line-height: 150%;text-align: justify;"><span class="s1">I am happy to inform you that on the recommendations of the referees,your paper titled</span>“<span style=" color: #974705;">'.$title.'</span>”<span class="s1">has been accepted for publication in</span><i>2019 9th International Conference on Management and Computer Science(ICMCS 2019).</i></p><p class="s1"style="padding-top: 8pt;padding-left: 5pt;text-indent: 0pt;text-align: justify;">Paper ID:<span class="h2">'.$paper_number.'</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s1"style="padding-left: 5pt;text-indent: 0pt;text-align: justify;">Publication fee:1700RMB;1900RMB(Include invoice);</p><p style="text-indent: 0pt;text-align: left;"><span><img width="400"height="143"alt="image"src="http://editormanage.com/Upload/001.png"/></span></p><p class="s1"style="padding-left: 5pt;text-indent: 0pt;line-height: 170%;text-align: left;"><i>2019</i>9<span class="s4">th</span>International Conference on Management and Computer Science(ICMCS 2019)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 5pt;text-indent: 0pt;line-height: 108%;text-align: justify;">2019 9th International Conference on Management and Computer Science(ICMCS 2019)will be held on March 15-17,2019.Shenyang,China.The conference is a great opportunity for researchers,developers and users from around the world in both industry and academia to share state-of-art results,explore new areas of research and development,and discuss emerging issues Management and Computer Science</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s5"style="padding-left: 5pt;text-indent: 0pt;text-align: justify;"><span class="h3">©</span>2019 9<span class="s6">th</span>International Conference on Management and Computer Science(ICMCS 2019)</p></body></html>
            ';
            pdf($html, $paper_number);
        }
      

  5.   

    $writer = '俊 莫 and 春梅 毛';
    我怎么知道 俊 莫 and 春梅 毛 是 utf-8 编码的? 
      

  6.   

    写到后面的html页面中了,页面设置的utf-8啊
      

  7.   

    现在就是用的writeHtml函数,怎么弄都是中文变问号,用write没事,但是格式没有
      

  8.   

    如果 ‘俊 莫 and 春梅 毛’是 gbk 编码的,你把它声明成 utf-8(<meta charset="utf-8">)的,那么必然导致乱码!
      

  9.   

     $writer = '俊 莫 and 春梅 毛';
      $a  = mb_detect_encoding($writer);
     p($a);die;
      

  10.   

    mb_detect_encoding 出现误判是大概率事件
    不然也不会再有个 mb_check_encoding 了
      

  11.   

    mb_check_encoding — Check if the string is valid for the specified encoding说明
    bool mb_check_encoding ([ string $var = NULL [, string $encoding = mb_internal_encoding() ]] )
    Checks if the specified byte stream is valid for the specified encoding. It is useful to prevent so-called "Invalid Encoding Attack". 
    参数var 
    The byte stream to check. If it is omitted, this function checks all the input from the beginning of the request. encoding 
    The expected encoding. 
    返回值
    成功时返回 TRUE, 或者在失败时返回 FALSE. 
    --------------------------------------------------------------------------------
      

  12.   

    返回的是true。
     $writer = '俊 莫 and 春梅 毛';
            $a  = mb_check_encoding ($writer);
            p($a);die;