PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
覆盖对比是将两个文件叠加在一起,并通过不同的颜色显示差异。叠加部分显示混合颜色。您可以设置两个文件的颜色、透明度以及混合模式。
以下是支持的混合模式:普通、正片叠底、滤色、叠加、变暗、变亮、颜色减淡、颜色加深、强光、柔光、差值、排除、色相、饱和度、颜色、明度。
// 获取对比文件的文件流。
const documentA = await fetch('https://example.com/documentA.pdf');
const documentABlob = await documentA.blob();
const documentAFile = new File([documentABlob], 'documentA.pdf');
const documentB = await fetch('https://example.com/documentB.pdf');
const documentBBlob = await documentB.blob();
const documentBFile = new File([documentBBlob], 'documentB.pdf');
const oldDocument = await instance.Core.createDocument(documentAFile); // 旧文档。
const newDocument = await instance.Core.createDocument(documentBFile); // 新文档。
// 覆盖对比文档。
const result = await oldDocument.compareDrawings(newDocument, {
baseAlpha: 0.5, // 旧文件的不透明度。
otherAlpha: 0.5, // 新文件的不透明度。
blendMode: instance.Core.Document.BlendMode.NORMAL, // 混合模式,如 'normal'、'multiply'、'screen'、'colorDodge'、'luminosity'。
colors: {
base: '#FBBDBF', // 旧文件的颜色。
other: '#93B9FD' // 新文件的颜色。
}
});
// 获取比较结果的文档blob对象。
const res = new Blob([await result.getFileData()], { type: 'application/pdf' });