簡體   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