ODF格式在线预览 发表于 2023-03-29 | 分类于 Components 安装依赖: npm i odf.js vue文件直接使用 123<div style="display:flex;justify-content: center;"> <div id="certificateWrapper" style="text-align: center"></div></div> 12345678910111213141516171819202122232425262728293031323334<script setup lang="ts">import { parseOfdDocument, renderOfd } from 'ofd.js'// 获取电子证照async function getPersonLicenseFile() { const res = await getPersonLicenseFileApi({ params: { certificateIdentifier:props.rowData.certificateIdentifier } }) if (res?.data) { parseOfdDocument({ // ofd写入文件地址 ofd: `data:image/${res?.data?.fileFormat};base64,${res?.data.content}`, success(res) { // 输出ofd每页的div const screenWidth = 350 const contentObj = renderOfd(screenWidth, res[0]) const contentDiv: any = document.getElementById('certificateWrapper') contentDiv.innerHTML = '' for (const div of contentObj) { contentDiv.appendChild(div) } }, fail(error) { console.log(error) } }) } else { root.$message.warning('尚未生成电子证书,请稍后再试') } loading.value = false}</script>