在 Windows 系統安裝 Sioyek 並且添加自定義 python 指令,如 extract highlight

Fred Lai
6 min readNov 29, 2024

--

在 Windows 從終端機安裝 Sioyek pdf 閱讀器,需要一些前置作業,以防自己忘記,把他記錄下來。

首先需要安裝 python

上網下載下來並安裝好之後,

可以輸入

pip install sioyek

但是可能會遇到以下畫面,這就是表示會需要安裝 Microsoft C++ Build Tools

  • 首先下載並安裝 Microsoft C++ Build Tools:
  • 前往:https://visualstudio.microsoft.com/visual-cpp-build-tools/
  • 點擊 “Download Build Tools”
  • 執行下載的安裝程式
  • 在安裝選項中,確保選擇了 “Desktop development with C++”
  • 安裝完 Build Tools 後,重新開啟命令提示字元並再次執行:
pip install sioyek

這時候應該沒問題了。

接下來,就是去 Sioyek 目錄底下新增相關的 python 代碼

找到根目錄底下的 prefs_user.config

在最後面可以加上這些代碼

# Paper Downloader
new_command _download_paper python -m sioyek.paper_downloader download "%{sioyek_path}" "%{paper_name}" "%{selected_text}"
control_click_command _download_paper

# Dual Panel
new_command _dual_panelify python -m sioyek.dual_panelify "%{sioyek_path}" "%{file_path}" "%{command_text}"

# Embed Annotations
new_command _embed_annotations python -m sioyek.embed_annotations "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}"

# Extract Highlights
new_command _extract_highlights python -m sioyek.extract_highlights "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%1" %{zoom_level}

# Translation
new_command _translate_selected_text python -m sioyek.translate "%{sioyek_path}" "%{selected_text}"
new_command _translate_current_line_text python -m sioyek.translate "%{sioyek_path}" "%{line_text}"

# Import Annotations
new_command _import_annotations python -m sioyek.import_annotations "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}"

# Remove Annotations
new_command _remove_annotations python -m sioyek.remove_annotation "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" "%{selected_rect}"

# Add Text
new_command _add_text python -m sioyek.add_text "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" "%{selected_rect}" "%{command_text}"
new_command _add_red_text python -m sioyek.add_text "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" "%{selected_rect}" "%{command_text}" fontsize=5 text_color=255,0,0

應該就可以成功了。

我這邊有稍微調整一下輸出的位置。如以下說明。

  1. 在配置文件中修改命令,添加輸出路徑:
new_command _extract_highlights python -m sioyek.extract_highlights "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" %{zoom_level} "/您想要的輸出路徑"
  1. 或者您可以設定 paper_folder_path:

# Set the paper folder path
paper_folder_path C:\Users\user\Downloads

# Extract Highlights command with explicit output path
new_command _extract_highlights python -m sioyek.extract_highlights "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" %{zoom_level} --output_path "C:\Users\user\Downloads"

這樣檔案就會可以輸出在我的下載資料夾下了。

具體作法,可以用 Sioyek 開啟一份 pdf ,然後選取喜歡的文字進行 highlight,滑鼠過去,按下 h + 任一字母,就會 highlight 起來。

要抽取 highlight 可以用” : ” 叫出指令

打入 extract highlight ,這時候就會輸出一份 pdf 把剛才整份檔案的 highlight 輸出了,非常方便。

--

--

Fred Lai
Fred Lai

Written by Fred Lai

Love is the ultimate answer.

No responses yet