LoginSignup
9
4

More than 5 years have passed since last update.

PDFやreveal.jsからpptxに変換(より良い方法)

Posted at

動機

パワポ嫌い!
下手だから上司が「フォント揃ってないね、舐めてるの?」とか言う!
だけど、reveal.js使ったら「何故パワポじゃないの?舐めてるの?」とか言う!
辛い(´;ω;`)

reveal.jsから場合

chromeでreveal.jsを開き、アドレス欄の末尾の
スラッシュとシャープを消して、?print-pdfを追加します。
すると印刷しても崩れなくなります。

印刷画面を出して、余白は無し、背景有りにします。
プレビューが綺麗になっていたらpdfとしてプリントします。

PDFから

ImageMagikを使って全部pngにして、
そのpngをpython-pptxでくっつけていけば良いです。
必要物品を入れます。

brew install imagemagick
brew install gs
pip install python-pptx

具体的には下記のようなコード書きました。
https://github.com/uesseu/pdf2pptx

from pptx import Presentation
from pptx.util import Inches
import sys
import os
import shutil


def main():
    fpath = sys.argv[1]
    out_file = sys.argv[2]
    tmp_dir = 'tmp'
    while(True):
        if os.path.exists('./' + tmp_dir):
            tmp_dir = tmp_dir + '_'
        else:
            break
    os.mkdir('./' + tmp_dir)
    tmp_img = './' + tmp_dir + '/tmp.png'
    os.system('convert ' + fpath + ' ' + tmp_img)
    pics_len = len(os.listdir('./' + tmp_dir))
    pics = ['./tmp-' + str(n) + '.png' for n in range(pics_len)]
    prs = Presentation()
    for pic in pics:
        blank_slide_layout = prs.slide_layouts[6]
        slide = prs.slides.add_slide(blank_slide_layout)
        left = top = Inches(0)
        left = Inches(0)
        pic = slide.shapes.add_picture('./' + tmp_dir + '/' + pic, left, top)
    prs.save(out_file)
    shutil.rmtree('./' + tmp_dir)


if __name__ == "__main__":
    main()

で、こいつを走らせれば変換できました。

python pdf2pptx.py in.pdf out.pptx

以上です…叩かないで…叩かないで…

9
4
0

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
9
4