Skip to content

Commit 36fbdbb

Browse files
834573: Optimized code using getPageInfo
1 parent a8e1fbd commit 36fbdbb

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

How to/Library Bounds to Viewer Bounds/src/app/app.component.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
[documentPath]="document"
2424
[serviceUrl]="serviceUrl"
2525
style="height: 640px; display: block;"
26-
(ajaxRequestSuccess)="handleAjaxRequestSuccess($event)"
2726
(exportSuccess)="handleExportSuccess($event)">
2827
</ejs-pdfviewer>
2928
</div>
@@ -46,26 +45,14 @@ import {
4645
export class AppComponent implements OnInit {
4746
public document: string = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
4847
public serviceUrl: string = 'https://services.syncfusion.com/js/production/api/pdfviewer';
49-
public pageSizes: any[] = [];
5048

51-
ngOnInit(): void {}
49+
ngOnInit(): void { }
5250

5351
findTextBounds() {
5452
const viewer = (document.getElementById('pdfViewer') as any).ej2_instances[0];
5553
console.log(viewer.textSearch.findText(['pdf', 'adobe'], false, 7));
5654
}
5755

58-
// Event for AJAX request success
59-
handleAjaxRequestSuccess(args: any) {
60-
if (args.action === 'Load') {
61-
const objLength = Object.keys(args.data.pageSizes).length;
62-
for (let x = 0; x < objLength; x++) {
63-
const pageSize = args.data.pageSizes[x];
64-
this.pageSizes.push(pageSize);
65-
}
66-
}
67-
}
68-
6956
// Event for export success
7057
handleExportSuccess(args: any) {
7158
const blobURL = args.exportData;
@@ -74,17 +61,17 @@ export class AppComponent implements OnInit {
7461
.then(objectData => {
7562
console.log(objectData);
7663
const shapeAnnotationData = objectData.pdfAnnotation[0].shapeAnnotation;
77-
shapeAnnotationData.forEach((data:any) => {
64+
shapeAnnotationData.forEach((data: any) => {
7865
if (data && data.rect && parseInt(data.rect.width)) {
79-
const pageHeight = this.pageSizes[parseInt(data.page)].Height;
80-
66+
const viewer = (document.getElementById('pdfViewer') as any).ej2_instances[0];
67+
const pageHeight = viewer.getPageInfo(parseInt(data.page)).height;
8168
// Converting PDF Library values into PDF Viewer values.
8269
const rect = {
8370
x: (parseInt(data.rect.x) * 96) / 72,
8471

8572
// Converting pageHeight from pixels(PDF Viewer) to points(PDF Library) for accurate positioning
8673
// The conversion factor of 72/96 is used to change pixel values to points
87-
y: (parseInt(pageHeight) * 72 / 96 - parseInt(data.rect.height)) * 96 / 72,
74+
y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72,
8875
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
8976
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
9077
};

0 commit comments

Comments
 (0)