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