繁体   English   中英

href不适用于mpdf中的动态网址

[英]a href is not working for dynamic url in mpdf

我在导出到PDF时在锚标记中遇到问题。锚标记适用于http://google.com等静态网址,但不适用于动态url。我正在将mpdf模块用于PDF。

$url = $fullBaseUrl.'/designers/attachment/time/'.$value['filetime'].'/uploadTab/imgattach'; 
// http://localhost/msme_latest/designers/attachment/time/1394432246/uploadTab/imgattach     

$html= '<a href="'.$url.'">'.$value['filename'].'</a>';        

// echo $html; die;

$mpdf->WriteHTML($html);
$mpdf->Output();
exit;

当我回显我的代码$ html时,它正确地给出了我的链接。但是当我将此代码导出为PDF时,它没有给出任何形式的链接PDF。 任何帮助将被申请。

为了解决这个问题,您必须使我在mpdf.php中进行更改

实际代码在第20146行的mpdf.php中

if(isset($vetor[1]) and $vetor[1] != '') //LINK
{
  if (strpos($vetor[1],".") === false && strpos($vetor[1],"@") !== 0) //assuming every external link has a dot indicating extension (e.g: .html .txt .zip www.somewhere.com etc.) 
  {
    //Repeated reference to same anchor?
    /*
    while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
        $this->internallink[$vetor[1]] = $this->AddLink();
        $vetor[1] = $this->internallink[$vetor[1]];
    */
  }
  $this->HREF = $vetor[1];                  // HREF link style set here ******
}

并且您只注释了代码行(行号:20151至20153)

        /*
        while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
            $this->internallink[$vetor[1]] = $this->AddLink();
            $vetor[1] = $this->internallink[$vetor[1]];
        */

并且您的pdf将接受所有链接,包括“ localhost”和其他外部链接。

使用Ip地址而不是localhost或使用Live服务器url对我有用

<?php
$fullBaseUrl = "http://127.0.0.1/meme_latest";
$url = $fullBaseUrl.'/designers/attachment/time/'.$value['filetime'].'/uploadTab/imgattach'; 
            //(http://localhost/msme_latest/designers/attachment/time/1394432246/uploadTab/imgattach)     
            $html= '<a href="'.$url.'">Test link</a>';        

            //echo $html; die;

include("../mpdf.php");

$mpdf=new mPDF(); 

$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>      

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM