如何將文字作為包含的 pdf 中的鏈接

如何將文字作為包含的 pdf 中的鏈接

我在 pdf 生成任務中包含了 pdf。是否可以用我包含的 pdf 文件中的可點擊文字替換文字。我的意思是添加文字連結。我要產生的 pdf 應該包含那些可替換的可點擊文字。我有從我包含的 pdf 中提取的一系列連結。我需要添加適當文字的連結。

 Array( 
[0] => Array(
    [text] => Text 1
    [href] => http://www.example.com
)
[1] => Array
(
    [text] => Text 2
    [href] => http://www.example.com
)
)

答案1

如果你要實施pdf乳膠在你的PHP應用。對我來說是代碼點火器

第1步:安裝pdflatex。

第 2 步:$ pdfannotextractor --install在終端機中安裝 pdfannotextractor

步驟 3:$ pdfannotextractor --version這將有助於在終端機中找到您的 PDFAnnotExtractor 版本。

步驟4:但是Pdfannotextractor還需要libpdfbox-java套件。否則我們會得到這個錯誤!錯誤:找不到 PDFBox 庫!

第 5 步:您可以從此連結下載 pdfboxhttps://sourceforge.net/projects/pdfbox/files/PDFBox/PDFBox-0.7.3/

步驟 6:解壓縮 zip 檔案並將解壓縮的資料夾複製並貼上到您的應用程式中。

第 7 步:請按照此代碼操作。

$file                   =   '/home/rebin/Downloads/file.pdf'; 

$pdflatex               =   '/usr/local/texlive/2016/bin/x86_64-linux/pdflatex';

$pdf_box                =   BASEPATH.'PDFBox-0.7.3/lib/PDFBox-0.7.3.jar';

$template_file          =   'user/join_template.tex';

$new_pdf_filename       =   'new_pdf';

$temp_join_file_path    =   'user/';

shell_exec("CLASSPATH='".$pdf_box.":%CLASSPATH%' pdfannotextractor ".$file);

$doc    =   '\documentclass{article}
        \usepackage{hyperref}
        \usepackage[left=1cm, right=1cm, top=2cm, bottom=2cm]{geometry}
        \usepackage{pdfpages}
        \usepackage{pax}
        \begin{document}
            \includepdf[page=-]{' . $file. '}
        \end{document}';

file_put_contents($template_file, $doc);

shell_exec($pdflatex . ' -output-directory=' . $temp_join_file_path . ' -jobname=' . $new_pdf_filename . ' -interaction=nonstopmode -shell-escape join_template.tex');

您的 pdf 文件將生成,且不缺少任何連結。

相關內容