在 Windows 11 中開啟 .tfii 圖片檔案,只能看的到一張圖片,使用工具轉換也只能將一張圖片轉換為 pdf ,這裡附上使用 python 將多張 .tiff 檔案轉換為 pdf 的程式碼:
需要安裝 pillow 套件。
參考資料:
stack overflow - How to convert multi image TIFF to PDF in python
import os
from PIL import Image
def convert_tif_to_pdf(input_path, output_path):
try:
image = Image.open(input_path)
images = []
for i in range(image.n_frames):
image.seek(i)
if image.mode != 'RGB':
images.append(image.convert('RGB'))
else:
images.append(image.copy())
images[0].save(output_path, 'PDF', save_all=True, append_images=images[1:])
print(f"Successfully converted {input_path} to {output_path}")
except Exception as e:
print(f"Error converting file: {str(e)}")
def main():
input_file = input("Enter the path to your TIF file: ")
output_file = os.path.splitext(input_file)[0] + '.pdf'
if not os.path.exists(input_file):
print("Input file does not exist!")
return
convert_tif_to_pdf(input_file, output_file)
if __name__ == "__main__":
main()
需要安裝 pillow 套件。
參考資料:
stack overflow - How to convert multi image TIFF to PDF in python
留言
張貼留言
如果有任何問題、建議、想說的話或文章題目推薦,都歡迎留言或來信: a@ruyut.com