# HTML을 SetTextFile 로 가져온 후 이미지 좌표 찾기

**URL:** <https://forum.developer.hancom.com/t/html-settextfile/2153>\
**Category:** 웹한글 기안기\
**Created:** [1월 21, 2025, 10:09오전 UTC](https://forum.developer.hancom.com/t/html-settextfile/2153 "2025-01-21T10:09:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user359](https://avatars.discourse-cdn.com/v4/letter/u/dec6dc/32.png) [@user359](https://forum.developer.hancom.com/u/user359)\
**Post date:** [1월 21, 2025, 10:09오전 UTC](https://forum.developer.hancom.com/t/html-settextfile/2153/1 "2025-01-21T10:09:31Z")

</div>

안녕하십니까

HTML을 가지고 SetTextFile API 로 한글을 불러오는 작업을 진행중입니다.

다름이 아니고 SetTextFile 한 다음 각각 그리기 객체 에 대해서 좌표 값을 가져온 후  
insertPicture를 하는것이 목적입니다.

html에서 이미지 는 3개가 존재하고  
해당 while 문 내 if문도 3번 타는데 GetPos 해서 좌표를 찍을경우

```
let setText = HwpCtrl.SetTextFile(html, "HTML", "insertfile", function (result) {

							var ctrl = HwpCtrl.HeadCtrl;
							var posObj;
		
							while (ctrl) {

								if (ctrl.CtrlID === 'gso') {

									posObj = HwpCtrl.GetPos();
                                    console.log('posObj.para : + ' + posObj.para);
									console.log('posObj.pos : ' + posObj.pos);

								}
                                   ctrl = ctrl.Next; }

}, null)

```

해당 부분 console을 찍어봐도 3번 모두 getpos 값이 동일합니다.  
비동기 문제인가 해서 promise 로 setText가 켜지고 (화면에도 hwp생성되고) 해도 마찬가지로  
getPos 값이 동일합니다 혹시 방법을 잘못 접근했을까요?

---

<div class="post-metadata">

**Author:** ![cgkang](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@cgkang](https://forum.developer.hancom.com/u/cgkang)\
**Post date:** [1월 22, 2025, 5:25오전 UTC](https://forum.developer.hancom.com/t/html-settextfile/2153/2 "2025-01-22T05:25:54Z")

</div>

안녕하세요.

while 문 안에 ctrl 이동이 빠져있습니다.  
아래 코드를 추가해서 테스트 하시기 바랍니다.  
“ctrl = ctrl.Next; //다음 ctrl로 이동”

감사합니다.

---

<div class="post-metadata">

**Author:** ![user359](https://avatars.discourse-cdn.com/v4/letter/u/dec6dc/32.png) [@user359](https://forum.developer.hancom.com/u/user359)\
**Post date:** [1월 22, 2025, 5:38오전 UTC](https://forum.developer.hancom.com/t/html-settextfile/2153/3 "2025-01-22T05:38:29Z")

</div>

위 게시글에는 빠져있는데  
ctrl = ctrl.Next 가 코드에 포함되어있습니다.

---

<div class="post-metadata">

**Author:** ![bart](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bart](https://forum.developer.hancom.com/u/bart)\
**Post date:** [1월 22, 2025, 8:43오전 UTC](https://forum.developer.hancom.com/t/html-settextfile/2153/4 "2025-01-22T08:43:13Z")

</div>

HwpCtrl.GetPos 를 통해 위치를 얻어오시면 현재 캐럿 위치를 가져오기 때문에 항상 같은 위치가 얻어질것 같습니다.

아래와 같이 ctrlcode 의 GetAnchorPos 를 사용하시면 개체의 위치를 얻어올 수 있습니다.

```javascript

var ctrl = HwpCtrl.HeadCtrl;
var posSet;

while (ctrl) {
    if (ctrl.CtrlID === 'gso') {
        posSet = ctrl.GetAnchorPos(0);
        console.log('pos.list : ' + posSet.Item("List"));
        console.log('pos.para : ' + posSet.Item("Para"));
        console.log('pos.pos : ' + posSet.Item("Pos"));

    }
    ctrl = ctrl.Next;      
}

```

감사합니다.
