0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

.docをpdfに変換する

Posted at

とりあえずのメモ。
.docxをpdf化するライブラリはpythonにあるが、.docは無さそうだったので。
指定したフォルダ内の.docをpdf化したものを同じフォルダ内に生成する。

sofficeコマンドを使用できるようにした後、以下を実行

doc_to_pdf.py
import os
import glob
import pathlib
import subprocess

path = "/Users/user/Downloads/doc_folder/" #ここでどのフォルダで変換したいか指定
p_temp = pathlib.Path(path)

for i in list(p_temp.glob('**/*')):
    dirname = os.path.dirname(i)
    root, extention = os.path.splitext(i)
    if extention == '.doc':
        convert_command = f"soffice --headless --convert-to pdf:writer_pdf_Export {i} --outdir {dirname}"
        subprocess.run(convert_command, shell=True)
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?