Dev Blog

스크립트 & 소스코드 공유

실무에서 유용하게 쓰는 스크립트와 코드 조각을 블로그 게시판으로 저장하고 공유합니다.

HTML5|JAVASCRIPT 웹페이지 인쇄 제어하기 - ScriptX 프린트 설정

페이지 정보

조회 197회 작성일 20-04-29 11:54
MeadCo ScriptX를 이용해 웹페이지 인쇄 시 머리말·꼬리말, 인쇄 방향(세로/가로), 여백, 배경 이미지 출력 여부를 제어하는 방법이다. object 태그로 ScriptX를 로드하고 factory.printing 속성을 설정하며, IE는 ScriptX, 크롬은 window.print()로 분기 처리하는 전체 예제 코드와 무료 라이선스 안내를 포함한다.

문서에서 출력하는 방식으로 출력합니다.

출력할 페이지에 아래의 코드를 삽입한다.

<!-- MeadCo ScriptX -->
<object id=factory style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="(자기경로)/smsx.cab#Version=7.4.0.8 "></object>

// 스크립트에 아래코드 추가
function printPage(){
factory.printing.header = "가로 페이지 인쇄"; //머릿말 설정
factory.printing.footer = ""; //꼬릿말 설정
factory.printing.portrait = false; //출력방향 설정: true-세로, false-가로
factory.printing.leftMargin = 1.0; //왼쪽 여백 설정
factory.printing.topMargin = 1.0; //위쪽 여백 설정
factory.printing.rightMargin = 1.0; //오른쪽 여백 설정
factory.printing.bottomMargin = 1.0; //아래쪽 여백 설정
// factory.printing.printBackground = true; //배경이미지 출력 설정:라이센스 필요
factory.printing.Print(false); //출력하기
}

// 인쇄버튼에서 해당 함수 실행
$( "#print" ).click(function(){
if( navigator.userAgent.indexOf("MSIE") > 0 ){
printPage();
} else if( navigator.userAgent.indexOf("Chrome") > 0){
window.print();
}
});

라이센스관련

http://scriptx.meadroid.com/license-pricing/free-deployment.aspx

Free Printing

A basic subset of ScriptX client-side printing functionality -- header & footer settings, printed orientation, coarse control of margins and a browser window/frame printing command -- is available at no charge, and is freely distributable.

ScriptX 클라이언트 측 인쇄 기능(헤더 및 바닥글 설정, 인쇄 방향, 여백의 거친 제어 및 브라우저 창/프레임 인쇄 명령)의 기본 하위 집합은 무료로 제공되며 무료로 배포됩니다.

배경이미지 크기 760 x 1102

<html>
<head>
<title>프린터 출력 테스트</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<STYLE media=print>
<!--
.noPrint{
DISPLAY: none
}
//-->
</STYLE>
</head>
<body>
<style>
body {
background:url('배경이미지') no-repeat center;
}
td {
font-size:26px;
font-family:궁서;
}
</style>

<table style="width:690px;">
<tr>
<td style="height:60px;">출력하기
</tr>
</table>
<table style="width:690px; height:400px;">
<tr>
<td> </td>
</tr>
</table>
<object id=factory style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://업로드주소/smsx.cab#Version=7,6,0,10 "></object>

<script language=javascript>
function init() {
var p = factory.printing;
var printername;
var defName;
var name;
try {
factory.printing.header = "";   //머릿말 설정');
factory.printing.footer = "";   //꼬릿말 설정');
factory.printing.portrait = true;  //출력방향 설정: false-가로, true-세로');
factory.printing.leftMargin = 0;  //왼쪽 여백 설정');
factory.printing.topMargin = 0;  //위쪽 여백 설정');
factory.printing.rightMargin = 0;  //오른쪽 여백 설정');
factory.printing.bottomMargin = 0;  //아래쪽 여백 설정');
factory.printing.Preview();
} catch ( e ) {}
}
init();
</script>
</body>
</html>

참고로 배경 이미지가 출력이 안될 경우 배경색 및 이미지 인쇄 앞에 체크가 안되어 있을때 안나옵니다.



Let's create something great together.

프로젝트 문의 및 견적 요청은 언제든 환영합니다.