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

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

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

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

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

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");
	}
}
1개의 좋아요

안녕하세요.

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

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; // <<<
		}
		...
	}
}

감사합니다.

1개의 좋아요