some code cleanup
This commit is contained in:
parent
d8399d8e32
commit
83e9f53940
@ -398,8 +398,6 @@ export class AnnotationActionsService {
|
||||
viewerAnnotation.setRotationControlEnabled(false);
|
||||
annotationManager.redrawAnnotation(viewerAnnotation);
|
||||
annotationManager.selectAnnotation(viewerAnnotation);
|
||||
|
||||
// console.log(viewerAnnotation);
|
||||
}
|
||||
|
||||
private async _extractTextAndPositions(viewer: WebViewerInstance, annotationId: string) {
|
||||
@ -407,35 +405,37 @@ export class AnnotationActionsService {
|
||||
|
||||
const document = await viewer.Core.documentViewer.getDocument().getPDFDoc();
|
||||
const page = await document.getPage(viewerAnnotation.getPageNumber());
|
||||
let quads = (<Core.Annotations.TextHighlightAnnotation>viewerAnnotation).Quads;
|
||||
if (!quads) {
|
||||
quads = [this._annotationDrawService.annotationToQuads(viewerAnnotation, viewer)];
|
||||
const rect = toPosition(viewerAnnotation.getPageNumber(), await page.getPageHeight(), quads[0]);
|
||||
if (viewerAnnotation instanceof Core.Annotations.TextHighlightAnnotation) {
|
||||
const words = [];
|
||||
const rectangles: IRectangle[] = [];
|
||||
for (const quad of viewerAnnotation.Quads) {
|
||||
const rect = toPosition(viewerAnnotation.getPageNumber(), await page.getPageHeight(), quad);
|
||||
rectangles.push(rect);
|
||||
const pdfNetRect = new viewer.Core.PDFNet.Rect(
|
||||
rect.topLeft.x,
|
||||
rect.topLeft.y,
|
||||
rect.topLeft.x + rect.width,
|
||||
rect.topLeft.y + rect.height,
|
||||
);
|
||||
const quadWords = await this._extractTextFromRect(viewer, page, pdfNetRect);
|
||||
words.push(...quadWords);
|
||||
}
|
||||
|
||||
return {
|
||||
text: words.join(' '),
|
||||
positions: rectangles,
|
||||
};
|
||||
} else {
|
||||
const rect = toPosition(
|
||||
viewerAnnotation.getPageNumber(),
|
||||
await page.getPageHeight(),
|
||||
this._annotationDrawService.annotationToQuads(viewerAnnotation, viewer),
|
||||
);
|
||||
return {
|
||||
positions: [rect],
|
||||
text: null,
|
||||
};
|
||||
}
|
||||
|
||||
const words = [];
|
||||
const rectangles: IRectangle[] = [];
|
||||
for (const quad of quads) {
|
||||
const rect = toPosition(viewerAnnotation.getPageNumber(), await page.getPageHeight(), quad);
|
||||
rectangles.push(rect);
|
||||
const pdfNetRect = new viewer.Core.PDFNet.Rect(
|
||||
rect.topLeft.x,
|
||||
rect.topLeft.y,
|
||||
rect.topLeft.x + rect.width,
|
||||
rect.topLeft.y + rect.height,
|
||||
);
|
||||
const quadWords = await this._extractTextFromRect(viewer, page, pdfNetRect);
|
||||
words.push(...quadWords);
|
||||
}
|
||||
|
||||
return {
|
||||
text: words.join(' '),
|
||||
positions: rectangles,
|
||||
};
|
||||
}
|
||||
|
||||
private async _extractTextFromRect(viewer: WebViewerInstance, page: Core.PDFNet.Page, rect: Core.PDFNet.Rect) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user