一个href不适用于mpdf中的动态URL

问题描述 投票:1回答:2

我在导出到PDF时出现锚标记问题.Anchor标记适用于http:google.com等静态网址,但它不适用于动态网址。我正在使用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。任何帮助都会得到满足。

php mpdf
2个回答
0
投票

使用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;
?>      

2
投票

要解决这个问题,你必须让我改变mpdf.php

实际代码在第1206行的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”和其他外部链接。

© www.soinside.com 2019 - 2024. All rights reserved.