在输出 PDF 时渲染 Unicode 扩展字符 Aspose.Cells for JavaScript 通过 C++
Contents
[
Hide
]
普通的Unicode字符长为2个字节,而Unicode补充字符长为4个字节。Aspose.Cells现在支持呈现这些4字节Unicode字符。
在Unicode字符标准中,补充字符是指分配的代码点范围从U+10000到U+10FFFF。换句话说,这些是大于U+FFFF的Unicode字符。
- 在UTF-8中,这些字符每个都是4个字节长。
- 在UTF-16中,这些字符需要2个代理对(16位单位)。
通过 C++ Aspose.Cells for JavaScript 在输出 PDF 时渲染 Unicode 扩展字符
以下截图展示了 Aspose.Cells 如何将 源 Excel 文件 转换为 输出 PDF。可以看到所有三个 Unicode 补充字符都被准确渲染,与 Microsoft Excel 完全一致。

示例代码
<!DOCTYPE html>
<html>
<head>
<title>Render Unicode Supplementary Characters to PDF</title>
</head>
<body>
<h1>Render Unicode Supplementary Characters to PDF</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Save the workbook as PDF
const outputData = workbook.save(SaveFormat.Pdf);
const blob = new Blob([outputData], { type: 'application/pdf' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'RenderUnicodeInOutput_out.pdf';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download PDF File';
document.getElementById('result').innerHTML = '<p style="color: green;">PDF generated successfully! Click the download link to get the PDF file.</p>';
});
</script>
</html>