# 매크로(JavaScript)로 PDF 변환 제작 중인데... 조언 부탁드립니다

**URL:** <https://forum.developer.hancom.com/t/javascript-pdf/2269>\
**Category:** 한글 오토메이션\
**Created:** [2월 27, 2025, 1:25오후 UTC](https://forum.developer.hancom.com/t/javascript-pdf/2269 "2025-02-27T13:25:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnDoe](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@JohnDoe](https://forum.developer.hancom.com/u/JohnDoe)\
**Post date:** [2월 27, 2025, 1:25오후 UTC](https://forum.developer.hancom.com/t/javascript-pdf/2269/1 "2025-02-27T13:25:26Z")

</div>

선생님들 안녕하세요. 조언 부탁드립니다.

현재 hwp,hwpx 파일을 PDF로 변환하는 매크로를 작성 하고 있습니다.  
단순히 한글 내 “매크로 정의” 기능을 통해서 파일 호출과 PDF저장을 짜깁기하고 배열만 추가 한 상태입니다.

현재 문제는 파일 호출 이후  
“다른 프로그램에서 이 파일은 사용 중이므로 쓸 수 없습니다.”  
메시지박스가 나오고 있습니다.  
호출 이후에 어떤 동작이 필요한걸까요…

버전은 2022이며, 아래는 스크립트 전문입니다

```auto
function OnScriptMacro_파일불러오기()
{
	var fileList = [
		"1.hwpx",
		"2.hwpx",
		"3.hwpx"
	]
	var filePath = "C:\\work\\_tempFile\\fileList\\";
	for (var i = 0; i < fileList.length; i++) {	
		HAction.GetDefault("FileOpen", HParameterSet.HFileOpenSave.HSet);
		with(HParameterSet.HFileOpenSave){
			OpenFlag = 0;	
			FileName = filePath + fileList[i];
			Attributes = 0;
		}
		HAction.Execute("FileOpen", HParameterSet.HFileOpenSave.HSet);
		HAction.GetDefault("FileSaveAsPdf", HParameterSet.HFileOpenSave.HSet);
		with(HParameterSet.HFileOpenSave){
			FileName = filePath + fileList[i];
			Format = "PDF";
			Attributes = i;	
		}
		HAction.Execute("FileSaveAsPdf", HParameterSet.HFileOpenSave.HSet);
		HAction.Run("Cancel");
	}
}

```

---

<div class="post-metadata">

**Author:** ![jhbang](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jhbang](https://forum.developer.hancom.com/u/jhbang)\
**Post date:** [2월 28, 2025, 12:43오전 UTC](https://forum.developer.hancom.com/t/javascript-pdf/2269/2 "2025-02-28T00:43:53Z")

</div>

안녕하세요.

저장하려는 PDF 파일 경로가 불러온 파일 경로와 동일하여 불러온 파일명에 저장하려는 시도 때문에  
파일 액세스 위반이 발생한건데요.  
저장시 FileName의 확장자를 변경시켜 저장하면 될 것 같습니다.  
그리고 Attributes의 값도 그냥 0으로 지정하시면 됩니다.

```auto
function OnScriptMacro_파일불러오기()
{
	var fileList = [
		"1.hwpx",
		"2.hwpx",
		"3.hwpx"
	]
	var filePath = "C:\\work\\_tempFile\\fileList\\";
	for (var i = 0; i < fileList.length; i++) {	
		...
		with(HParameterSet.HFileOpenSave){
			FileName = filePath + fileList[i]; // <<< 
			Format = "PDF";
			Attributes = i; // <<<
		}
		...
	}
}

```

감사합니다.
