Skip to content

Commit

Permalink
#2148 allow to pass both native pdf.js coordinate and percentages
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed Feb 26, 2024
1 parent e4d4eaa commit 8ddc80f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10281,7 +10281,7 @@ function getDocument(src) {
}
const fetchDocParams = {
docId,
apiVersion: "4.1.700",
apiVersion: "4.1.701",
data,
password,
disableAutoFetch,
Expand Down Expand Up @@ -12038,8 +12038,8 @@ class InternalRenderTask {
}
}
}
const version = "4.1.700";
const build = "482c452ab";
const version = "4.1.701";
const build = "00113bc03";

;// CONCATENATED MODULE: ./src/shared/scripting_utils.js
function makeColorComp(n) {
Expand Down Expand Up @@ -18644,8 +18644,8 @@ class DrawLayer {



const pdfjsVersion = "4.1.700";
const pdfjsBuild = "482c452ab";
const pdfjsVersion = "4.1.701";
const pdfjsBuild = "00113bc03";

var __webpack_exports__AbortException = __webpack_exports__.AbortException;
var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56747,7 +56747,7 @@ class WorkerMessageHandler {
docId,
apiVersion
} = docParams;
const workerVersion = "4.1.700";
const workerVersion = "4.1.701";
if (apiVersion !== workerVersion) {
throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
}
Expand Down Expand Up @@ -57322,8 +57322,8 @@ if (typeof window === "undefined" && typeof self !== "undefined" && isMessagePor

;// CONCATENATED MODULE: ./src/pdf.worker.js

const pdfjsVersion = "4.1.700";
const pdfjsBuild = "482c452ab";
const pdfjsVersion = "4.1.701";
const pdfjsBuild = "00113bc03";

var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler;
export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler };
Original file line number Diff line number Diff line change
Expand Up @@ -6912,7 +6912,7 @@ const GenericL10n = null;
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ ngxExtendedPdfViewerVersion: () => (/* binding */ ngxExtendedPdfViewerVersion)
/* harmony export */ });
const ngxExtendedPdfViewerVersion = '19.4.0';
const ngxExtendedPdfViewerVersion = '19.4.0-alpha.2';

/***/ }),

Expand Down Expand Up @@ -15073,7 +15073,7 @@ class PDFViewer {
#outerScrollContainer = undefined;
#pageViewMode = "multiple";
constructor(options) {
const viewerVersion = "4.1.700";
const viewerVersion = "4.1.701";
if (pdfjs_lib__WEBPACK_IMPORTED_MODULE_0__.version !== viewerVersion) {
throw new Error(`The API version "${pdfjs_lib__WEBPACK_IMPORTED_MODULE_0__.version}" does not match the Viewer version "${viewerVersion}".`);
}
Expand Down Expand Up @@ -18942,8 +18942,8 @@ _app_js__WEBPACK_IMPORTED_MODULE_3__ = (__webpack_async_dependencies__.then ? (a



const pdfjsVersion = "4.1.700";
const pdfjsBuild = "482c452ab";
const pdfjsVersion = "4.1.701";
const pdfjsBuild = "00113bc03";
const AppConstants = {
LinkTarget: _pdf_link_service_js__WEBPACK_IMPORTED_MODULE_2__.LinkTarget,
RenderingStates: _ui_utils_js__WEBPACK_IMPORTED_MODULE_0__.RenderingStates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export interface PDFExportScaleFactor {

type DirectionType = 'ltr' | 'rtl' | 'both' | undefined;

export interface PdfImageParameters {
urlOrDataUrl: string;
page?: number;
left?: number | string;
bottom?: number | string;
right?: number | string;
top?: number | string;
rotation?: 0 | 90 | 180 | 270;
}

export interface Line {
x: number;
y: number;
Expand Down Expand Up @@ -509,17 +519,16 @@ export class NgxExtendedPdfViewerService {
return imageBlob;
}

public async addImageToAnnotationLayer(
urlOrDataUrl: string,
page: number,
left: number | string,
bottom: number | string,
right: number | string,
top: number | string,
rotation: 0 | 90 | 180 | 270
): Promise<void> {
await this.renderPage(page);
public async addImageToAnnotationLayer({ urlOrDataUrl, page, left, bottom, right, top, rotation }: PdfImageParameters): Promise<void> {
const PDFViewerApplication: IPDFViewerApplication = (window as any).PDFViewerApplication;

if (page) {
if (page !== this.currentPageIndex()) {
await this.renderPage(page);
}
} else {
page = this.currentPageIndex();
}
const previousAnnotationEditorMode = PDFViewerApplication.pdfViewer.annotationEditorMode;
this.switchAnnotationEdtorMode(13);
const dataUrl = await this.loadImageAsDataURL(urlOrDataUrl);
Expand All @@ -531,33 +540,41 @@ export class NgxExtendedPdfViewerService {
const width = rightDim - leftDim;
const height = topDim - bottomDim;

const leftPdf = this.convertToPDFCoordinates(left, width);
const bottomPdf = this.convertToPDFCoordinates(bottom, height);
const rightPdf = this.convertToPDFCoordinates(right, width);
const topPdf = this.convertToPDFCoordinates(top, height);
const leftPdf = this.convertToPDFCoordinates(left, width, 0);
const bottomPdf = this.convertToPDFCoordinates(bottom, height, 0);
const rightPdf = this.convertToPDFCoordinates(right, width, width);
const topPdf = this.convertToPDFCoordinates(top, height, height);

const stampAnnotation: StampEditorAnnotation = {
annotationType: 13,
pageIndex: page,
bitmapUrl: dataUrl,
rect: [leftPdf, bottomPdf, rightPdf, topPdf],
rotation,
rotation: rotation ?? 0,
};
console.log(stampAnnotation);
this.addEditorAnnotation(stampAnnotation);
await this.sleep(10);
this.switchAnnotationEdtorMode(previousAnnotationEditorMode);
}

private convertToPDFCoordinates(top: string | number, height: number): number {
if (typeof top === 'string') {
if (top.endsWith('%')) {
return (parseInt(top, 10) / 100) * height;
public currentPageIndex(): number {
const PDFViewerApplication: IPDFViewerApplication = (window as any).PDFViewerApplication;
return PDFViewerApplication.pdfViewer.currentPageNumber;
}

private convertToPDFCoordinates(value: string | number | undefined, maxValue: number, defaultValue: number): number {
if (!value) {
return defaultValue;
}
if (typeof value === 'string') {
if (value.endsWith('%')) {
return (parseInt(value, 10) / 100) * maxValue;
} else {
return parseInt(top, 10);
return parseInt(value, 10);
}
} else {
return top;
return value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const isEdge = typeof navigator === 'undefined' || /Edge\/\d./i.test(navigator.u
const needsES5 = typeof ReadableStream === 'undefined' || typeof Promise['allSettled'] === 'undefined';

export const pdfjsVersion = '4.0.850';
export const pdfjsBleedingEdgeVersion = '4.1.700';
export const pdfjsBleedingEdgeVersion = '4.1.701';
export function getVersionSuffix(folder: string): string {
if (folder?.includes('bleeding-edge')) {
return pdfjsBleedingEdgeVersion;
Expand Down

0 comments on commit 8ddc80f

Please sign in to comment.