PPT를 PDF와 이미지로 변환하기 - 파이썬과 LibreOffice로 pptx 슬라이드를 PNG로
PPT(pptx)를 PDF로 바꾸는 가장 쉬운 방법은 LibreOffice를 설치하고 파이썬에서 soffice --headless --convert-to pdf 명령을 실행하는 것이다. 슬라이드를 PNG 이미지로 만들려면 그 PDF를 PyMuPDF로 쪽마다 그림으로 저장한다. python-pptx는 파일을 만들고 고치는 라이브러리라 PDF나 그림으로 저장하는 기능이 없다. PDF를 그림으로 바꾸는 방법은 Python으로 PDF를 이미지로 변환하기에서 더 자세히 다뤘다.
이 글의 코드는 LibreOffice 26.8, PyMuPDF 2.2, python-pptx 1.0.2(리눅스)에서 실행해 확인했고, 코드 아래의 결과는 실제 출력이다. 윈도우 PowerPoint 방식은 실행 환경이 없어 코드만 싣고 실행하지 않았다.
한눈에 보기
| 방법 | 필요한 것 | 결과 | 쓰는 곳 |
|---|---|---|---|
| LibreOffice headless | LibreOffice | 리눅스 서버, 맥, 윈도우 모두 | |
| PDF → PNG (PyMuPDF) | pip install pymupdf |
슬라이드마다 PNG | 썸네일, 영상, 웹 게시 |
| PowerPoint COM | 윈도우 + PowerPoint | PDF, PNG | 원본과 똑같은 모양이 필요할 때 |
설치
LibreOffice는 운영체제마다 설치 방법이 다르다.
# 우분투
sudo apt install libreoffice-impress fonts-nanum
# 맥(Homebrew)
brew install --cask libreoffice
# 파이썬 라이브러리
pip install pymupdf python-pptx
윈도우는 libreoffice.org에서 설치 파일을 받는다. 명령 이름은 soffice인데, 운영체제마다 위치가 다르다.
| 운영체제 | soffice 경로 |
|---|---|
| 리눅스 | soffice (PATH에 등록됨) |
| 맥 | /Applications/LibreOffice.app/Contents/MacOS/soffice |
| 윈도우 | C:\Program Files\LibreOffice\program\soffice.exe |
예제 PPT 만들기
변환할 pptx가 있다면 건너뛴다. 여기서는 python-pptx로 한글 슬라이드 세 장을 만든다.
from pptx import Presentation
prs = Presentation()
for i, (title, body) in enumerate([("3분기 실적 보고", "매출 12% 증가"),
("지역별 거래량", "서울, 경기 순으로 많음"),
("다음 분기 계획", "신규 지점 2곳 개설")], 1):
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = f"{i}. {title}"
slide.placeholders[1].text = body
prs.save("report.pptx")
print(len(prs.slides))
3
PPT를 PDF로 변환하기 (soffice –convert-to pdf)
subprocess.run()으로 LibreOffice를 화면 없이(headless) 실행한다. --outdir은 결과를 둘 폴더다. 결과 파일 이름은 원본 이름에 확장자만 .pdf로 바뀐다.
import subprocess
from pathlib import Path
def pptx_to_pdf(src, outdir="pdf", soffice="soffice", timeout=120):
outdir = Path(outdir)
outdir.mkdir(exist_ok=True)
result = subprocess.run(
[soffice, "--headless", "--convert-to", "pdf", "--outdir", str(outdir), str(src)],
capture_output=True, text=True, timeout=timeout,
)
pdf = outdir / (Path(src).stem + ".pdf")
if not pdf.exists():
raise RuntimeError(f"변환 실패: {result.stdout} {result.stderr}")
return pdf
pdf = pptx_to_pdf("report.pptx")
print(pdf, pdf.stat().st_size > 0)
pdf/report.pdf True
성공 여부는 결과 파일이 생겼는지로 확인했다. 파일을 읽지 못하면 아래처럼 LibreOffice가 남긴 메시지가 오류에 담긴다. 맥이나 윈도우에서는 soffice= 인자에 위 표의 경로를 넣는다.
try:
pptx_to_pdf("없는파일.pptx")
except RuntimeError as e:
print(e)
변환 실패: Error: source file could not be loaded
여러 파일을 한 번에 변환하기
파일 이름을 여러 개 주면 LibreOffice를 한 번만 띄워 차례로 변환한다. 파일마다 따로 실행하는 것보다 빠르다.
import shutil
for name in ["a.pptx", "b.pptx"]:
shutil.copy("report.pptx", name)
result = subprocess.run(["soffice", "--headless", "--convert-to", "pdf", "--outdir", "pdf", "a.pptx", "b.pptx"],
capture_output=True, text=True, timeout=300)
print(result.stdout.strip())
convert /w/work/2026-12-03-pptx-to-pdf-image/a.pptx as a Impress document -> /w/work/2026-12-03-pptx-to-pdf-image/pdf/a.pdf using filter : impress_pdf_Export
convert /w/work/2026-12-03-pptx-to-pdf-image/b.pptx as a Impress document -> /w/work/2026-12-03-pptx-to-pdf-image/pdf/b.pdf using filter : impress_pdf_Export
PDF를 슬라이드별 PNG 이미지로 저장하기
PDF 한 쪽이 슬라이드 한 장이다. PyMuPDF로 쪽마다 get_pixmap()을 불러 PNG로 저장한다. dpi가 해상도다. 기본 4:3 슬라이드(10인치 폭)는 dpi=96이면 960픽셀, 16:9 슬라이드(13.33인치 폭)는 dpi=144면 1920픽셀이 된다.
import pymupdf
def pdf_to_pngs(pdf, outdir="slides", dpi=150):
outdir = Path(outdir)
outdir.mkdir(exist_ok=True)
paths = []
for page in pymupdf.open(pdf):
pix = page.get_pixmap(dpi=dpi)
path = outdir / f"slide_{page.number + 1}.png"
pix.save(path)
paths.append((path.name, pix.width, pix.height))
return paths
print(pdf_to_pngs("pdf/report.pdf", dpi=96))
[('slide_1.png', 960, 720), ('slide_2.png', 960, 720), ('slide_3.png', 960, 720)]
JPG가 필요하면 pix.save("slide_1.jpg", jpg_quality=85)처럼 확장자만 바꾸면 된다.

pptx를 바로 PNG로 바꾸면 첫 장만 나온다
--convert-to png도 있지만 결과는 첫 슬라이드 한 장뿐이다.
subprocess.run(["soffice", "--headless", "--convert-to", "png", "--outdir", "direct", "report.pptx"],
capture_output=True, timeout=120)
print(sorted(p.name for p in Path("direct").iterdir()))
['report.png']
슬라이드 전체가 필요하면 PDF를 거치는 위 방법을 쓴다. 두 함수를 묶으면 이렇다.
def pptx_to_pngs(src, dpi=150):
pdf = pptx_to_pdf(src, outdir="pdf")
return pdf_to_pngs(pdf, outdir=Path("slides") / Path(src).stem, dpi=dpi)
print(len(pptx_to_pngs("report.pptx")))
3
윈도우에서 PowerPoint로 변환하기 (comtypes, pywin32)
윈도우에 PowerPoint가 설치돼 있으면 파이썬에서 PowerPoint를 직접 움직여 변환할 수 있다. 결과가 PowerPoint 화면과 똑같다는 것이 장점이다. 이 글의 실행 환경(리눅스)에서는 돌릴 수 없어 아래 코드는 실행하지 않았다.
# pip install comtypes (윈도우 + PowerPoint 필요, 실행하지 않은 코드)
import comtypes.client
from pathlib import Path
src = Path("report.pptx").resolve() # PowerPoint에는 절대 경로를 줘야 한다
powerpoint = comtypes.client.CreateObject("PowerPoint.Application")
deck = powerpoint.Presentations.Open(str(src), WithWindow=False)
deck.SaveAs(str(src.with_suffix(".pdf")), 32) # 32 = ppSaveAsPDF
for i, slide in enumerate(deck.Slides, 1):
slide.Export(str(src.parent / f"slide_{i}.png"), "PNG", 1920, 1080)
deck.Close()
powerpoint.Quit()
pywin32를 쓴다면 import win32com.client 후 win32com.client.Dispatch("PowerPoint.Application")로 바꾸면 나머지는 같다. 사용자가 로그인하지 않은 서버나 예약 작업에서는 PowerPoint가 잘 안 뜨므로, 서버에서 돌릴 일이라면 LibreOffice 방식이 낫다.
한글이 사라지거나 깨질 때: 글꼴 설치
리눅스 서버나 도커에서 변환하면 한글이 통째로 빠진 PDF가 나오는 일이 흔하다. 서버에 한글 글꼴이 없기 때문이다. 글꼴이 없는 서버를 흉내 내려고, 글꼴 설정(fontconfig) 파일로 LibreOffice가 영문 글꼴(DejaVu)만 보게 하고 변환해 본다.
import os
conf = """<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/usr/share/fonts/truetype/dejavu</dir>
<cachedir>/tmp/fc-cache-nofont</cachedir>
</fontconfig>"""
Path("no_korean.conf").write_text(conf)
env = dict(os.environ, FONTCONFIG_FILE=str(Path("no_korean.conf").resolve()))
subprocess.run(["soffice", "--headless", "--convert-to", "pdf", "--outdir", "no_font", "report.pptx"],
capture_output=True, timeout=120, env=env)
pymupdf.open("no_font/report.pdf")[0].get_pixmap(dpi=60).save("no_font.png")

숫자와 점만 남고 한글은 보이지 않는다. 그런데 텍스트로 뽑아 보면 한글이 들어 있다. 글자는 있는데 그릴 글꼴이 없어서 빈칸이 된 것이다.
for name in ["no_font/report.pdf", "pdf/report.pdf"]:
page = pymupdf.open(name)[0]
fonts = sorted({f[3].split("+")[-1] for f in page.get_fonts()})
print(name, fonts, repr(page.get_text()[:12]))
no_font/report.pdf ['DejaVuSans'] '1. 3 분기 실적 보'
pdf/report.pdf ['DejaVuSans', 'NanumGothic'] '1. 3\n \n \n분기실'
글꼴 목록을 보면 원인이 바로 보인다. 정상 PDF에는 NanumGothic이 있고, 깨진 PDF에는 영문 글꼴 DejaVuSans뿐이다. 변환 결과가 이상하면 이렇게 PDF에 들어간 글꼴부터 확인한다.
해결은 서버에 한글 글꼴을 설치하는 것이다.
# 우분투, 데비안
sudo apt install fonts-nanum fonts-noto-cjk
fc-cache -f
fc-list :lang=ko family # 설치된 한글 글꼴 확인
도커 이미지라면 Dockerfile에 RUN apt-get update && apt-get install -y fonts-nanum을 넣는다.
맑은 고딕으로 만든 PPT의 줄바꿈이 달라진다
윈도우에서 맑은 고딕으로 만든 PPT를 리눅스에서 변환하면, LibreOffice가 맑은 고딕 대신 설치된 다른 한글 글꼴(나눔고딕 등)로 그린다. 글자 폭이 달라서 줄바꿈 위치나 글상자 넘침이 원본과 달라질 수 있다. 같은 모양이 꼭 필요하면 원본에 쓴 글꼴 파일을 서버의 ~/.fonts나 /usr/share/fonts에 넣고 fc-cache -f를 실행한다. 글꼴 파일을 서버에 복사해도 되는지는 글꼴 사용 허락 조건을 확인한다. 처음부터 나눔고딕이나 Noto Sans KR처럼 무료 글꼴로 템플릿을 만들어 두면 이 문제가 없다.
자주 겪는 문제
변환이 조용히 실패하거나 멈춘다
LibreOffice는 사용자 프로필 폴더를 한 번에 하나의 프로세스만 쓰게 한다. 그래서 LibreOffice 창을 띄워 둔 채로 변환하거나 여러 변환을 동시에 돌리면, 결과 파일 없이 끝나는 일이 생길 수 있다. 변환마다 프로필 폴더(-env:UserInstallation)를 따로 주면 서로 부딪치지 않는다. 아래는 두 파일을 동시에 변환한 예다.
from concurrent.futures import ThreadPoolExecutor
def convert_isolated(src, n):
profile = Path(f"/tmp/lo_profile_{n}").resolve().as_uri()
subprocess.run(["soffice", f"-env:UserInstallation={profile}", "--headless",
"--convert-to", "pdf", "--outdir", f"pdf_{n}", src],
capture_output=True, timeout=180)
return Path(f"pdf_{n}", Path(src).stem + ".pdf").exists()
with ThreadPoolExecutor(2) as pool:
print(list(pool.map(convert_isolated, ["a.pptx", "b.pptx"], [1, 2])))
[True, True]
timeout을 꼭 준다. 손상된 파일에서 LibreOffice가 멈추면 파이썬도 함께 멈춘다.
soffice를 찾을 수 없다는 오류
FileNotFoundError: 'soffice'는 PATH에 없다는 뜻이다. 맥과 윈도우는 위 표의 전체 경로를 soffice= 인자로 준다.
애니메이션, 동영상
PDF와 PNG에는 슬라이드의 마지막 모습만 들어간다. 애니메이션 단계나 슬라이드 속 동영상은 담기지 않는다.
PPT 파일을 코드로 만드는 방법은 python-pptx 표 넣기와 PPT 템플릿 텍스트 일괄 바꾸기에, 만들어진 PDF를 합치거나 나누는 방법은 Python으로 PDF 합치기, 나누기, 회전하기에 정리했다.
자주 묻는 질문
파이썬으로 pptx를 PDF로 바꾸려면?
LibreOffice를 설치하고 subprocess.run(["soffice", "--headless", "--convert-to", "pdf", "--outdir", "출력폴더", "파일.pptx"])를 실행한다. python-pptx에는 PDF로 저장하는 기능이 없다.
pptx 슬라이드를 한 장씩 PNG 이미지로 저장하려면?
먼저 PDF로 바꾼 뒤 PyMuPDF로 쪽마다 page.get_pixmap(dpi=150).save("slide_1.png")를 부른다. soffice --convert-to png는 첫 슬라이드 한 장만 저장한다.
리눅스 서버에서 변환하면 한글이 사라진다. 왜 그런가?
서버에 한글 글꼴이 없기 때문이다. 우분투라면 sudo apt install fonts-nanum 후 fc-cache -f로 글꼴을 설치하면 된다. 문서에 쓴 글꼴(예: 맑은 고딕)이 없으면 다른 한글 글꼴로 바뀌어 줄바꿈 위치가 달라질 수 있다.
윈도우에서 PowerPoint로 바로 변환할 수 있나?
PowerPoint가 설치돼 있으면 comtypes나 pywin32로 PowerPoint를 불러 SaveAs(경로, 32)로 PDF를 만들 수 있다. 결과가 PowerPoint 화면과 가장 비슷하지만 윈도우와 PowerPoint가 있어야 한다.
PDF 변환이 아무 출력 없이 끝나거나 멈춘다.
LibreOffice 창이 열려 있거나 여러 변환을 동시에 돌리면 사용자 프로필이 겹쳐 결과 파일 없이 끝날 수 있다. 다른 사용자 프로필을 쓰게 -env:UserInstallation=file:///tmp/lo_profile을 붙이고, subprocess.run()에 timeout을 준다.
참고한 문서
- https://help.libreoffice.org/latest/en-US/text/shared/guide/start_parameters.html
- https://pymupdf.readthedocs.io/en/latest/page.html#Page.get_pixmap
- https://learn.microsoft.com/en-us/office/vba/api/powerpoint.presentation.saveas
댓글남기기