PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
弧长测量工具可用于绘制曲线和圆弧,以测量用户选择的图形的弧长。
弧长测量工具有两类:曲线测量工具与圆弧测量工具。


配置测量属性后,可通过以下步骤创建弧长测量注释:
Tools.ToolNames.CURVE_MEASUREMENT;如果创建的是圆弧测量,则使用 Tools.ToolNames.ARC_MEASUREMENT),在创建时将默认属性和工具的 Measure 附加到测量注释上。再用 Annotations 中对应的类创建测量注释,并使用 annotationManager 的 addAnnotation 方法添加。以下是创建曲线测量注释的示例代码:
ComPDFKitViewer(...)
.then(instance => {
const { documentViewer, annotationManager, Annotations, Tools } = instance.Core;
documentViewer.addEventListener('documentLoaded', async () => {
// 进入曲线测量注释创建模式。
instance.UI.setToolbarGroup('toolbarGroup-Measure');
instance.UI.setToolMode(Tools.ToolNames.CURVE_MEASUREMENT);
// 为注释设置默认测量属性。
const curveTool = documentViewer.getTool(Tools.ToolNames.CURVE_MEASUREMENT);
const { StrokeColor, StrokeThickness, Opacity, Font, FontSize } = curveTool.defaults;
const annotation = new Annotations.FreeHandAnnotation({
PageNumber: 1,
StrokeColor,
StrokeThickness,
Opacity,
Font,
FontSize
});
annotation.Measure = { ...curveTool.Measure };
// 曲线的起点、两个控制点和终点。
annotation.setCurveControlPoints([
new Annotations.Point(106, 366),
new Annotations.Point(200, 440),
new Annotations.Point(288, 323),
new Annotations.Point(390, 367)
]);
// 创建测量注释。
await annotationManager.addAnnotation(annotation);
// 渲染注释。
annotationManager.drawAnnotationsFromList([annotation]);
});
});以下是创建圆弧测量注释的示例代码:
ComPDFKitViewer(...)
.then(instance => {
const { documentViewer, annotationManager, Annotations, Tools } = instance.Core;
documentViewer.addEventListener('documentLoaded', async () => {
// 进入圆弧测量注释创建模式。
instance.UI.setToolbarGroup('toolbarGroup-Measure');
instance.UI.setToolMode(Tools.ToolNames.ARC_MEASUREMENT);
// 为注释设置默认测量属性。
const arcTool = documentViewer.getTool(Tools.ToolNames.ARC_MEASUREMENT);
const { StrokeColor, StrokeThickness, Opacity, Font, FontSize } = arcTool.defaults;
const annotation = new Annotations.ArcAnnotation({
PageNumber: 1,
StrokeColor,
StrokeThickness,
Opacity,
Font,
FontSize
});
annotation.Measure = { ...arcTool.Measure };
annotation.setMeasurementDisplayOptions(arcTool.getDefaultMeasurementDisplayOptions());
// 起点、弧上一点和终点。
annotation.setPath([
new Annotations.Point(92, 225),
new Annotations.Point(233, 169),
new Annotations.Point(143, 98)
]);
// 创建测量注释。
await annotationManager.addAnnotation(annotation);
// 渲染注释。
annotationManager.drawAnnotationsFromList([annotation]);
});
});