Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why dompdf does not recognize the "target" attribute in the HTML code?

Tags:

html

php

dompdf

Why dompdf doesn't recognize the target="_blank" attribute ? What can I do to make this work ? I also tried with target = "_tab". This is my code :

  <?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");
?>
like image 418
Attila Naghi Avatar asked Jun 05 '26 18:06

Attila Naghi


1 Answers

dompdf uses the URI action to provide linking support (see section 7.5.3 of the PDF 1.3 spec). This action does not support supplying a target window for the link.

It's easy to see how viewing a PDF in the browser that you might expect to have this functionality. The PDF document is just one more tab/window in the browser. However, if you think about PDF documents in isolation the lack of this functionality is understandable. A PDF document opened directly on your computer would open in an app, and clicking any URI links would load via an external app (the web browser). So the PDF spec does not have any knowledge of windows/tabs, especially the version of the spec currently targeted by dompdf.

like image 151
BrianS Avatar answered Jun 08 '26 07:06

BrianS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!