사용자 정의 글꼴은 PDFFontsManager.registerFont 함수를 사용하여 등록될 수 있습니다. 셀 스타일을 고객 글꼴로 설정하면 Spread.Sheets는 PDF로 내보낼 때 해당 글꼴을 등록합니다.
PDFFontsManager.fallbackFont 함수를 재정의하여 특정 글꼴 문자열에 대한 사용자 정의 글꼴 파일을 제공합니다.
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 2});
initSpread(spread);
};
function initSpread(spread) {
document.getElementById('savePDF').onclick = function () {
spread.savePDF(function (blob) {
saveAs(blob, 'download.pdf');
}, console.log);
};
var data = report, fontsObj = fonts;
spread.fromJSON(data);
var sheet = spread.getActiveSheet();
sheet.setColumnWidth(0, 50);
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(2, 60);
sheet.setColumnWidth(3, 60);
// register the specific custom font
registerCustomFont(fontsObj);
// add custom font to fontManager
addFontsToFontManager(fontsObj);
// setting printInfo
setPrintInfo(spread);
}
function registerCustomFont(fontsObj) {
var fonts = {
normal: fontsObj["simkai.ttf"]
};
GC.Spread.Sheets.PDF.PDFFontsManager.registerFont('simkai', fonts);
}
function addFontsToFontManager(fontsObj) {
var fonts = {
normal: fontsObj["MTCORSVA.TTF"]
};
GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = function (font) {
var fontInfoArray = font.split(' '), fontName = fontInfoArray[fontInfoArray.length - 1];
if (fontName === 'mtcorsva') {
return fonts.normal;
}
}
}
function setPrintInfo(spread) {
var sheet = spread.getActiveSheet();
var printInfo = sheet.printInfo();
printInfo.showBorder(true);
printInfo.showGridLine(false);
printInfo.showColumnHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
printInfo.showRowHeader(GC.Spread.Sheets.Print.PrintVisibilityType.hide);
printInfo.centering(GC.Spread.Sheets.Print.PrintCentering.horizontal);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="ko-kr"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/FileSaver.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-print/dist/gc.spread.sheets.print.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-pdf/dist/gc.spread.sheets.pdf.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/fonts.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/pdfExportData.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-spreadsheets"></div>
<div class="options-container">
<p>Click this button to save the workbook in Spread with its own custom fonts to a PDF file.</p>
<div class="option-row">
<input type="button" value="Export PDF" id="savePDF">
</div>
</div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
input {
padding: 8px 14px;
display: block;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}