为什么dompdf无法识别" target" HTML代码中的属性?

时间:2014-05-05 11:40:06

标签: php html dompdf

为什么dompdf无法识别target="_blank“属性?我可以做些什么来完成这项工作?我也试过target = "_tab"。这是我的代码:

  <?php
    error_reporting(0); ini_set("gd.jpeg_ignore_warning", 1); set_include_path(get_include_path() . PATH_SEPARATOR . "dompdf"); require_once('dompdf/dompdf_config.inc.php');
    $fk_marca = $_GET['id'];$fk_familia = $_GET['m'];$session = $_GET['session'];
    $img_url = $_GET['img_url'];$titleCategoria = $_GET['title'];$nr_of_lines = $_GET['nr_of_lines'];
    $dompdf = new DOMPDF();
    $img  = "background-image:url('http://acros.netlogiq.info/dompdf/img/pic.png');background-repeat:no-repeat;";
    $img2 = "background-image:url('http://acros.netlogiq.info/dompdf/img/pic2.png');";
    $img3 = "background-image:url('http://acros.netlogiq.info/dompdf/img/Dungi6.png');background-repeat:no-repeat;";
    $header = '<div id="imageHeader" style="'.$img3.';width:1000px;">
                <div style="width:400px;">
                    <p style="margin-left:80px;font-weight:bold;padding-top:30px;font-family: \'Trebuchet MS\', \'Lucida Grande\', \'Lucida Sans Unicode\', \'Lucida Sans\', Tahoma, sans-serif;">MANUAL T&Eacute;CNICO</p>
                    <p style="margin-left:80px;padding-top:-8px;font-weight:bold;font-family: \'Trebuchet MS\', \'Lucida Grande\', \'Lucida Sans Unicode\', \'Lucida Sans\', Tahoma, sans-serif;">FAMILIA:<span>&nbsp;&nbsp;&nbsp;</span>'.$titleCategoria.'</p>
                </div>
                    <img  style="margin-left:700px;margin-top:-110px;" src ="http://acros.netlogiq.info/'.$img_url.'">
                    <div style="margin-left:725px;width:15px;margin-top:-20px;background-color:white;font-weight:bold;"><span class="pagenum">&nbsp;</span></div>
            </div></div><br><br><br><br>';
    $link = mysql_connect('localhost', 'netlogiq_attin', 'attin');
    $db = mysql_select_db("netlogiq_acros");
    if ($fk_familia == 0 ){
        $and = "fk_familia ='$fk_marca' ";
    }else{
        $and = "fk_marca = '$fk_familia' and fk_familia = '$fk_marca'";
    }
    $query = "select articulo,descripcion,imagen,link,precio,codigo from prod_detalle where ".$and." ";
    $select = mysql_query($query);
    $count_query = mysql_num_rows($select);
    $count = 1;
    $html = '<html>
        <style>
           <style>
            @page { margin: 180px 50px; }
            #imageHeader { position: fixed; height: 120px; margin-left:-50px;margin-top:-50px;}    
            .pagenum:after { content: counter(page); }
        </style>'.$header.'<br><br> ';
    while ($row = mysql_fetch_array($select)){
        $url = $row['imagen'];
        $title = $row['articulo'];
        $file = 'txt/textarea.txt';
        $desc =  $row['descripcion'];
        $link =  $row['link'];
        $codigo = $row['codigo'];
        if (empty($session))
            $price = " ";
        else
        $price = "<div style='margin-left:420px;'><span style='color:red;font-size:22px;'><b>".$row['precio']."&euro;</b></span></div>";
        if (empty($link)){
            $link = '&nbsp;';
        }else{
            $link = '&nbsp;&nbsp;<a  target="_blank" href ="'.$link.'">Link Fabricante</a>';
        }
        file_put_contents($file, $desc);
        $handle = fopen($file, "r");
        if ($handle) {
            $text ="";$i = 1;
            while (($buffer = fgets($handle, 4096)) !== false) {
                if ($i <= 9 ){
                    if ($buffer !=""){
                        $text = $text.$buffer;
                    }
                }
                $i++;
            }
            fclose($handle);
        }
        $wh ="";
        list($width, $height, $type, $attr) = getimagesize("http://acros.netlogiq.info/fotos/".$url); // get image info
        $ratio = $width/$height;
        if( $ratio > 2) {
            $width = 170;
            $height = 200/$ratio;
            $wh = "width:".$width."px;height:".$height."px;margin-left:-30px;margin-top:40px;";
        }elseif($ratio > 1.4 && $ratio < 2){
            $width = 170;
            $height = 160/$ratio;
            $wh = "width:".$width."px;height:".$height."px;margin-left:-30px;margin-top:30px;";
        }elseif($ratio <= 1 && $ratio > 1.099){
            $width = 160;
            $height = 144/$ratio;
            $wh = "width:".$width."px;height:".$height."px;margin-left:-24px;margin-top:10px;";
        }elseif($ratio >= 1.099 && $ratio <= 1.4){
            $width = 170;
            $height = 160/$ratio;
            $wh = "width:".$width."px;height:".$height."px;margin-left:-30px;margin-top:10px;";
        }elseif ($ratio < 1  && $ratio > 0.72) {
            $width = 80;
            $height = 80;
            $wh = "width:".$width."px;height:".$height."px;margin-left:16px;margin-top:40px;";
        }elseif ($ratio <= 0.72) {
            $width = 70;
            $height = 80;
            $wh = "width:".$width."px;height:".$height."px;margin-left:16px;margin-top:40px;";
        }else{
            $width = 70;
            $height = 80;
            $wh = "width:".$width."px;height:".$height."px;margin-left:16px;margin-top:40px;";
        }
        if ($count != 1){
            if (($count - 1) % 4 == 0){
                $marginTop = "padding-top:-76px;";
            }else{
                $marginTop ="padding-top:0px;";
            }
        }
        $html .= ' <div style="'.$marginTop.'">
            <div style="float:left;margin-left:-50px;padding-left:90px;height:200px;'.$img.'">
                <img src = "http://acros.netlogiq.info/fotos/'.$url.'" style="'.$wh.'">
            </div>';
        $html.= '<div style="padding-left:300px;margin-left:-35px;width:500px;height:160px;padding-top:10px;'.$img2.'">
                <span style="color:#574595;font-family: \'Arial Rounded MT Bold\', \'Helvetica Rounded\', Arial, sans-serif;"><b style="">'.$codigo.' '.$title.' </b></span><br>
                '.$price.'
                <span style="font-size:12px;font-family: \'Trebuchet MS\', \'Lucida Grande\', \'Lucida Sans Unicode\', \'Lucida Sans\', Tahoma, sans-serif;">'.$text.'</span>
                </div><div style="clear:both"></div><br></div><div style="clear:both"></div>'.$link.'';
                    if ($count % 4 == 0){
                        if($count !=  $count_query){
                            $html.='<p style="page-break-before: always;"></p><br><br><br><br><br><br><br><br><br><br>';
                        }else{
                            $html.='';
                        }
                    }elseif(($count % 4 != 0) && ($count ==  $count_query)){
                            $html.=' ';
                    }
        $count ++;
    }
    $html .='</html>';
    $dompdf->load_html($html);
    $dompdf->render();
    $output = $dompdf->output();
    file_put_contents("pdf_generated/file.pdf", $output);
    header("Location: http://acros.netlogiq.info/pdf_generated/file.pdf");
?>

1 个答案:

答案 0 :(得分:2)

dompdf使用URI操作来提供链接支持(see section 7.5.3 of the PDF 1.3 spec)。此操作不支持为链接提供目标窗口。

很容易看到如何在浏览器中查看您可能希望拥有此功能的PDF。 PDF文档只是浏览器中的另一个选项卡/窗口。但是,如果您单独考虑PDF文档,则缺少此功能是可以理解的。直接在您的计算机上打开的PDF文档将在应用程序中打开,单击任何URI链接将通过外部应用程序(Web浏览器)加载。所以PDF规范没有任何关于windows / tabs的知识,尤其是目前dompdf所针对的规范版本。