# 인쇄할 쪽 번호가 없습니다. 오류

**URL:** <https://forum.developer.hancom.com/t/topic/3082>\
**Category:** 한글 오토메이션\
**Created:** [3월 13, 2026, 1:57오전 UTC](https://forum.developer.hancom.com/t/topic/3082 "2026-03-13T01:57:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FZUku2](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@FZUku2](https://forum.developer.hancom.com/u/FZUku2)\
**Post date:** [3월 13, 2026, 1:57오전 UTC](https://forum.developer.hancom.com/t/topic/3082/1 "2026-03-13T01:57:40Z")

</div>

모아찍기가 기본으로 설정된 문서를 포함해서 모든 문서를 한페이지당 하나씩 인쇄하는 옵션으로 hwp파일을 pdf로 변환해주는 automation python코드를 작성하려고 합니다.

코드는 아래와 같은데, 해당 코드를 실행하면 “인쇄할 쪽 번호가 없습니다” 오류가 발생합니다.

비슷한 오류를 겪었거나, 해결 방법을 아시는 분이 계시다면 도움이 필요합니다…

승승아빠-한글매크로를 기반으로 작성한 코드입니다.

def convert\_hwp\_to\_pdf(self, hwp\_path, pdf\_path):

```
    pythoncom.CoInitialize()

    hwp = None

    try:

        hwp = win32com.client.gencache.EnsureDispatch('HWPFrame.HwpObject')

        hwp.XHwpWindows.Item(0).Visible = True

        hwp.RegisterModule("FilePathCheckDLL", "FilePathCheckerModule")

        hwp.Open(hwp_path, "", "forceopen:true;versionwarning:false;")

        hwp.Run("MoveDocEnd")

        time.sleep(0.5)

        hwp.Run("MoveDocBegin")

        time.sleep(0.5)

        \# ---------------------------------------------------------

        \# \[핵심 조치\] 3. 페이지가 0인지 체크 (빈 문서 방어)

        \# ---------------------------------------------------------

        if hwp.PageCount == 0:

            print(f"⚠️ 경고: {hwp_path} 파일의 페이지가 0쪽입니다. 인쇄를 건너뜁니다.")

            return # 빈 문서이므로 인쇄하지 않고 함수 종료

        \# HWP 팝업창 무시 (매우 중요!)

        \# 0x10000 = 사용자 입력 대기 안 함, 0x20000 = 경고창 표시 안 함

        hwp.SetMessageBoxMode(0x10000 | 0x20000)

        hwp.HAction.Run("AcceptAllRevisions") # 모든 변경 사항 반영

        hwp.HAction.Run("TrackChanges") # 변경 추적 기능 끄기

        \# -----------------------------

        \# 인쇄 설정 초기화

        \# -----------------------------

        hwp.Run("MoveDocBegin")

        time.sleep(1)

        hwp.HAction.GetDefault("Print", hwp.HParameterSet.HPrint.HSet)

        \# ===== 매크로 설정 그대로 적용 =====

        \# 인쇄 방식 (1 = 공급 용지 맞춤)

        hwp.HParameterSet.HPrint.PrintMethod = 1

        \# 부수 정렬

        hwp.HParameterSet.HPrint.Collate = 1

        hwp.HParameterSet.HPrint.UserOrder = 0

        \# 파일로 출력

        hwp.HParameterSet.HPrint.PrintToFile = 1

        \# 전체 문서

        hwp.HParameterSet.HPrint.Range = 0

        \# PDF 프린터

        hwp.HParameterSet.HPrint.PrinterName = "Microsoft Print to PDF"

        \# 출력 파일

        hwp.HParameterSet.HPrint.filename = pdf_path

        \# 페이지 번호 사용

        hwp.HParameterSet.HPrint.UsingPagenum = 0

        hwp.HParameterSet.HPrint.ReverseOrder = 0

        hwp.HParameterSet.HPrint.Pause = 0

        hwp.HParameterSet.HPrint.PrintImage = 1

        hwp.HParameterSet.HPrint.PrintDrawObj = 1

        hwp.HParameterSet.HPrint.PrintClickHere = 0

        hwp.HParameterSet.HPrint.PrintAutoFootnoteLtext = ""

        hwp.HParameterSet.HPrint.PrintAutoFootnoteCtext = ""

        hwp.HParameterSet.HPrint.PrintAutoFootnoteRtext = ""

        hwp.HParameterSet.HPrint.PrintAutoHeadnoteLtext = ""

        hwp.HParameterSet.HPrint.PrintAutoHeadnoteCtext = ""

        hwp.HParameterSet.HPrint.PrintAutoHeadnoteRtext = ""

        hwp.HParameterSet.HPrint.PrintFormObj = 1

        hwp.HParameterSet.HPrint.PrintMarkPen = 0

        hwp.HParameterSet.HPrint.PrintMemo = 0

        hwp.HParameterSet.HPrint.PrintMemoContents = 0

        hwp.HParameterSet.HPrint.PrintRevision = 1

        hwp.HParameterSet.HPrint.PrintBarcode = 1

        hwp.HParameterSet.HPrint.Flags = 8192

        \# Device = Printer

        hwp.HParameterSet.HPrint.Device = 0

        hwp.HParameterSet.HPrint.PrintPronounce = 0

        hwp.HParameterSet.HPrint.NumCopy = 0

        \# -----------------------------

        \# 인쇄 실행

        \# -----------------------------

        hwp.HAction.Execute("Print", hwp.HParameterSet.HPrint.HSet)

        time.sleep(2)

        \# time.sleep(2) 대신 파일이 생성될 때까지 대기

        timeout = 2

        elapsed = 0

        while not os.path.exists(pdf_path) or os.path.getsize(pdf_path) == 0:

            time.sleep(1)

            elapsed += 1

            if elapsed > timeout:

                break

    finally:

        if hwp:

            hwp.Clear(1) # 종료 시 저장 여부를 묻는 팝업 방지

            hwp.Quit()

        pythoncom.CoUninitialize()

```

---

<div class="post-metadata">

**Author:** ![FZUku2](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@FZUku2](https://forum.developer.hancom.com/u/FZUku2)\
**Post date:** [3월 13, 2026, 2:11오전 UTC](https://forum.developer.hancom.com/t/topic/3082/2 "2026-03-13T02:11:23Z")

</div>

해결한 코드 남겨 놓고 갑니다  
pythoncom.CoInitialize()

```
    hwp = win32com.client.Dispatch("HWPFrame.HwpObject")

    try:

        hwp.XHwpWindows.Item(0).Visible = True

        hwp.RegisterModule("FilePathCheckDLL", "FilePathCheckerModule")

        hwp.Open(hwp_path)

        \# PrintToPDFEx 액션 생성

        act = hwp.CreateAction("PrintToPDFEx")

        set = act.CreateSet()

        act.GetDefault(set)

        set.SetItem("FileName", pdf_path)

        set.SetItem("Collate", 1)

        set.SetItem("UserOrder", 0)

        set.SetItem("PrintToFile", 0)

        set.SetItem("NumCopy", 1)

        \# PDF 프린터

        set.SetItem("PrinterName", "Microsoft Print to PDF")

        set.SetItem("UsingPagenum", 1)

        set.SetItem("ReverseOrder", 0)

        set.SetItem("Pause", 0)

        set.SetItem("PrintImage", 1)

        set.SetItem("PrintDrawObj", 1)

        set.SetItem("PrintClickHere", 0)

        set.SetItem("PrintAutoFootnoteLtext", "^f")

        set.SetItem("PrintAutoFootnoteCtext", "^t")

        set.SetItem("PrintAutoFootnoteRtext", "^P쪽 중 ^p쪽")

        set.SetItem("PrintAutoHeadnoteLtext", "^c")

        set.SetItem("PrintAutoHeadnoteCtext", "^n")

        set.SetItem("PrintAutoHeadnoteRtext", "^p")

        set.SetItem("PrintFormObj", 1)

        set.SetItem("PrintMarkPen", 0)

        set.SetItem("PrintMemo", 0)

        set.SetItem("PrintMemoContents", 0)

        set.SetItem("PrintRevision", 1)

        set.SetItem("PrintBarcode", 1)

        set.SetItem("PrintPronounce", 0)

        \# 인쇄 방식

        set.SetItem("PrintMethod", 0)

        \# 실행

        act.Execute(set)

    finally:

        try:

            hwp.Quit()

        except:

            pass

        pythoncom.CoUninitialize()

```
