setPrintHeader(false); //不要頁首 $pdf->setPrintFooter(false); //不要頁尾 $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); //設定自動分頁 $pdf->setFontSubsetting(true); //產生字型子集(有用到的字才放到文件中) $pdf->SetMargins(15, 15); //設定頁面邊界, $pdf->AddPage(); //新增頁面,一定要有,否則內容出不來 include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php'); $sn = system_CleanVars($_REQUEST, 'sn', 0, 'int'); $myts = MyTextSanitizer::getInstance(); $tbl = $xoopsDB->prefix('snews'); $sql = "SELECT * FROM `$tbl` WHERE `sn` = '{$sn}'"; $result = $xoopsDB->query($sql) or web_error($sql); $snews = $xoopsDB->fetchArray($result); $content = $myts->displayTarea($snews['content'], 1, 0, 0, 0, 0); $content = strip_word_html($content); $html = new Tidy(); $tidy_options = array('clean' => true, 'indent' => true); $html->parseString($content, $tidy_options, 'utf8'); $html->cleanRepair(); // die($html); $title = $myts->htmlSpecialChars($snews['title']); $username = $myts->htmlSpecialChars($snews['username']); //$pdf->Text( $x, $y, $txt, $fstroke = false, $fclip = false, $ffill = true, $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M', $rtloff = false ); $pdf->SetFont('droidsansfallback', '', 24, '', true); //設定字型 $pdf->Text($pdf->GetX(), $pdf->GetY(), $title, false, false, true, 0, 1); $pdf->SetFont('msungstdlight', '', 12, '', true); //設定字型 $pdf->Text($pdf->GetX(), $pdf->GetY(), $username, false, false, true, 0, 1); $pdf->writeHTML($html, 1, 0); //PDF內容設定 $pdf->Output('snews.pdf', 'I'); function strip_word_html($text, $allowed_tags = '') { mb_regex_encoding('UTF-8'); //replace MS special characters first $search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u'); $replace = array('\'', '\'', '"', '"', '-'); $text = preg_replace($search, $replace, $text); if (mb_stripos($text, '/*') !== false) { $text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm'); } $text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text); $text = strip_tags($text, $allowed_tags); $text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $text); $search = array('#<(strong|b)[^>]*>(.*?)(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)(em|i)>#isu', '#]*>(.*?)#isu'); $replace = array('$2', '$2', '$1'); $text = preg_replace($search, $replace, $text); $num_matches = preg_match_all("/\
') { mb_regex_encoding('UTF-8'); //replace MS special characters first $search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u'); $replace = array('\'', '\'', '"', '"', '-'); $text = preg_replace($search, $replace, $text); if (mb_stripos($text, '/*') !== false) { $text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm'); } $text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text); $text = strip_tags($text, $allowed_tags); $text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ' '), $text); $search = array('#<(strong|b)[^>]*>(.*?)(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)(em|i)>#isu', '#]*>(.*?)#isu'); $replace = array('$2', '$2', '$1'); $text = preg_replace($search, $replace, $text); $num_matches = preg_match_all("/\