首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我想在ng2-pdf-viewer中突出显示一个矩形

我想在ng2-pdf-viewer中突出显示一个矩形
EN

Stack Overflow用户
提问于 2020-11-18 12:17:45
回答 1查看 396关注 0票数 0

我已经创建了一个OCR应用程序,当一个pdf文件被处理时,我得到一个边界框,它显示了我想要使用的pdf文件中的文本的坐标,并在我的pdf查看器中突出显示它。我使用的是ng2-pdf-viewer。

代码语言:javascript
运行
复制
<pdf-viewer *ngIf='extension=="pdf" || extension == "PDF"' [src]="selectedPDF[index]"
          [original-size]="true" [fit-to-page]="true" class="pdf-viewer-class">
</pdf-viewer>

我已经尝试了2-3种方法,但它们都不起作用,而且我无法在网上找到解决方案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-20 12:17:38

在html中:

代码语言:javascript
运行
复制
<canvas #myCanvas width="860px" height="1106px" style="z-index: 20;position: absolute;left: 0;"></canvas>
          <pdf-viewer id="pdfViewerID" *ngIf='extension=="pdf" || extension == "PDF"' [src]="selectedPDF[index]"
            (after-load-complete)="afterLoadComplete($event)" [show-all]="false" [(page)]='pageNumber'
            [original-size]="true" [fit-to-page]="true" class="pdf-viewer-class"
            [render-text]="true" [render-text-mode]="2">
          </pdf-viewer>

在Ts中:

代码语言:javascript
运行
复制
 @ViewChild('myCanvas') myCanvas: ElementRef<HTMLCanvasElement>;
    
      public context: CanvasRenderingContext2D;
    this.context = this.myCanvas.nativeElement.getContext('2d');
    this.context.beginPath();
            var editedboundingBox = this.getOuterRectanglePoints(boundingBox);
            this.context.moveTo(editedboundingBox[0],editedboundingBox[1]);
            this.context.lineTo(editedboundingBox[2],editedboundingBox[3]);
            this.context.lineTo(editedboundingBox[4],editedboundingBox[5]);
            this.context.lineTo(editedboundingBox[6],editedboundingBox[7]);
            this.context.lineTo(editedboundingBox[0],editedboundingBox[1]);
            this.context.fillStyle = 'rgb(255, 153, 171, 0.3)';
            this.context.fill();
            this.context.strokeStyle = 'darkred';
            this.context.lineWidth = 2;
            this.context.stroke();
            this.context.closePath();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64887027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档