Hyperlink Path Garbled in PDF Using fitz.LINK_LAUNCH #4335
Unanswered
bagwechien
asked this question in
Looking for help
Replies: 2 comments 6 replies
-
You could try using this: link_path = "E:/健行科技大學/智慧機械概論/期末報告/期末報告-4CLI.PDF" Instead of this: link_path = r"E:\健行科技大學\智慧機械概論\期末報告\期末報告-4CLI.PDF" |
Beta Was this translation helpful? Give feedback.
1 reply
-
But maybe the deeper problem are the Chinese letters ... |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The program opens input.pdf, adds a piece of text (PDF) and a hyperlink, then saves it as output.pdf.
The program runs without errors, but when I open output.pdf and click on the hyperlink, the path appears as:
E:冥衄秂æ−•大å, which is clearly garbled and different from the path I specified, making it impossible to open the target file.
I tried using uri, which works for opening external links, but I need a relative path, so I had to switch back to using fitz.LINK_LAUNCH.
Does anyone know how to resolve this issue?
import subprocess
import fitz
import chardet
def add_text_with_link(pdf_path, output_path, text, link_path):
try:
doc = fitz.open(pdf_path)
except Exception as e:
print("無法開啟 PDF: ", e)
return
input_pdf = "input.pdf" # 輸入的 PDF
output_pdf = "output.pdf" # 輸出的 PDF
link_path = r"E:\健行科技大學\智慧機械概論\期末報告\期末報告-4CLI.PDF" # 本地超連結檔案路徑
bom_text = "PDF"
if bom_text:
# 在 PDF 中加入 BOM 文字與超連結
add_text_with_link(input_pdf, output_pdf, bom_text, link_path)
Beta Was this translation helpful? Give feedback.
All reactions