[Delphi] 웹브라우져 컨트롤을 이용하여 출력하기

2026. 6. 6. 21:18·Programming/Delphi

웹브라우져 컨트롤을 이용하여 출력하기
델파이로 프로그램 작업을 하다가
출력물이 필요해서 웹브라우져 컨트롤을 이용한 출력 프로그램을 만들었습니다.
델파이 스타터 버전에는 퀵리포트나 패스트 리포트가 없어서
HTML 을 디자인 하고 웹브라우져 컨트롤로 표시한후 출력하면 되겠다는 생각에
만들어 보게 되었습니다.

 

출력 데이터 생성

var
  htmltext, errmsg: String;
  Fp: TextFile;
  IOError : integer;
begin
  htmltext := '<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">' + #10#13;

  htmltext := htmltext + '<table border="1">';
  htmltext := htmltext + '<tr><td>성명</td><td>' + Edit1.Text + '</td></tr>';
  htmltext := htmltext + '<tr><td>생년월일</td><td>' + Edit2.Text + '</td></tr>';
  htmltext := htmltext + '<tr><td>연락처</td><td>' + Edit3.Text + '</td></tr>';
  htmltext := htmltext + '</table>';

  AssignFile(fp, 'C:\TEMP\tmp.html');
  {$I-}
  ReWrite(Fp);
  {$I+}

  IOError := IOResult;
  if IOError <> 0 then begin
    errmsg := '파일 쓰기 실패. IOResult = ' + IntToStr(IOError);
    exit;
  end;

  Writeln(Fp, htmltext);
  CloseFile(Fp);

  frmPrint := TfrmPrint.Create(Application);
  frmPrint.ShowModal;
  frmPrint.Free;
end;

 

출력물 폼 디자인

//form show 이벤트에서 tmp.html 불러오기
WebBrowser1.Navigate('C:\TEMP\tmp.html');

// 출력버튼
var
  vIn, vOut: OleVariant;
begin
  // 출력
  WebBrowser1.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, vIn, vOut);
end;

// 프린터 설정
var
  vIn, vOut: OleVariant;
begin  
  WebBrowser1.ControlInterface.ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER, vIn, vOut);
end;

 

HTML 파일로 저장하고 웹브라우져 컨트롤에서 읽어 오면
출력 컴포넌트 없이 간단하 출력물 작성이 가능합니다.

'Programming > Delphi' 카테고리의 다른 글

[Delphi] 프로그래밍 팁 모음  (0) 2026.06.09
[Delphi] 웹으로 파일 전송(POST) 하는 프로그램  (0) 2026.06.08
DirectShow 기본 Cam 프로그램  (0) 2026.05.31
[Delphi] 진법변환 (16->10, 10->2, 2->16. 10->8, 2->8)  (0) 2026.05.21
[Delphi] SAPI 컴포넌트 등록 방법(TTS 구현)  (0) 2026.05.20
'Programming/Delphi' 카테고리의 다른 글
  • [Delphi] 프로그래밍 팁 모음
  • [Delphi] 웹으로 파일 전송(POST) 하는 프로그램
  • DirectShow 기본 Cam 프로그램
  • [Delphi] 진법변환 (16->10, 10->2, 2->16. 10->8, 2->8)
레이조(RayCho)
레이조(RayCho)
개발자 레이조(RayCho)의 블로그입니다. 똑똑하게 배우고 기록하는 공간
  • 레이조(RayCho)
    레이(Ray)의 개발이야기
    레이조(RayCho)
  • 전체
    오늘
    어제
    • 분류 전체보기 (73) N
      • Programming (73) N
        • Python (5)
        • Flutter (4)
        • Delphi (25)
        • Lazarus (1)
        • C#.NET (13) N
        • ASP.NET (5)
        • Database (6)
        • Game Dev (5)
        • Web (6)
        • ETC (3)
  • 블로그 메뉴

    • 홈
    • Introduce
    • 태그
    • 방명록
  • 링크

    • Naver Blog
    • Diary Blog
  • 공지사항

  • 인기 글

  • 태그

    Python
    개발환경
    iis
    ASP.NET
    프로그래밍
    기초
    objectpascal
    delphi
    csharp
    웹프로그래밍
    델파이
    PSP
    C#
    mssql
    Flutter
    C++
    VCL
    POST
    소스코드
    Web
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
레이조(RayCho)
[Delphi] 웹브라우져 컨트롤을 이용하여 출력하기
상단으로

티스토리툴바