아래아한글(hwp) 자동화

[파이썬으로 아래아 한글(hwp) 자동화] 여러 개의 파일을 인쇄할 때, 프린트 대화상자의 "인쇄" 버튼 클릭 방법

pandas-py 2020. 3. 16. 16:36

HwpCtrl API.hwp
0.43MB

다수의 한글(hwp) 파일을 인쇄해야 할 때가 있다. 각 파일에서 프린트 아이콘(Ctrl + P) 클릭 후에 인쇄 버튼을 누르기 번거롭다. 아래와 같은 코드(신명진님 코드 참조)를 통해서

  1. 파일을 열고
  2. 프린트 아이콘을 누르고
  3. 인쇄 버튼을 클릭해야 자동화가 완성된다.

1과, 2는 잘 되었으나 (3)을 자동화하는데 실패했다.

for file in files:
	#file은 절대 경로로 작성되어야 함
    hwp = win32.gencache.EnsureDispatch('HWPFrame.HwpObject')
    hwp.RegisterModule('FilePathCheckDLL', 'SecurityModule')
    hwp.open(file)
    hwp.HAction.GetDefault('Print', hwp.HParameterSet.HPrint.HSet)
    hwp.HAction.Run('Print')

또한 붙임의 파일(HwpCtrl API.hwp, 출처: 한글과 컴퓨터 개발자료실)의 205페이지에 나오는 메시지 박스의 종류(아래 코드)에 해당되지 않았다. 1번부터 6번까지 다 시도해 보았으나 "인쇄" 버튼이 눌러지지 않았다. 끝까지 시도해 보자.

// 메시지 박스의 종류
#define MB_MASK						0x00FFFFFF
// 1. 확인(MB_OK) : IDOK(1)
#define MB_OK_IDOK						0x00000001
#define MB_OK_MASK						0x0000000F
// 2. 확인/취소(MB_OKCANCEL) : IDOK(1), IDCANCEL(2)
#define MB_OKCANCEL_IDOK					0x00000010
#define MB_OKCANCEL_IDCANCEL				0x00000020
#define MB_OKCANCEL_MASK					0x000000F0
// 3. 종료/재시도/무시(MB_ABORTRETRYIGNORE) : IDABORT(3), IDRETRY(4), IDIGNORE(5)
#define MB_ABORTRETRYIGNORE_IDABORT			0x00000100
#define MB_ABORTRETRYIGNORE_IDRETRY			0x00000200
#define MB_ABORTRETRYIGNORE_IDIGNORE			0x00000400
#define MB_ABORTRETRYIGNORE_MASK				0x00000F00
// 4. 예/아니오/취소(MB_YESNOCANCEL) : IDYES(6), IDNO(7), IDCANCEL(2)
#define MB_YESNOCANCEL_IDYES				0x00001000
#define MB_YESNOCANCEL_IDNO				0x00002000
#define MB_YESNOCANCEL_IDCANCEL				0x00004000
#define MB_YESNOCANCEL_MASK				0x0000F000
// 5. 예/아니오(MB_YESNO) : IDYES(6), IDNO(7)
#define MB_YESNO_IDYES					0x00010000
#define MB_YESNO_IDNO					0x00020000
#define MB_YESNO_MASK					0x000F0000
// 6. 재시도/취소(MB_RETRYCANCEL) : IDRETRY(4), IDCANCEL(2)
#define MB_RETRYCANCEL_IDRETRY				0x00100000
#define MB_RETRYCANCEL_IDCANCEL				0x00200000
#define MB_RETRYCANCEL_MASK				0x00F00000

 

반응형