@vue-pdf-viewer/viewer
Version:
A vue-pdf-viewer component for Vue and Nuxt. Suitable for vue-pdf document.
34 lines (33 loc) • 1.72 kB
TypeScript
/**
* Calculate the proper rect for highlight annotation serialization
*
* This method replicates the getRect logic from PDF.js AnnotationEditor to ensure
* that outlines are properly serialized when saving documents. The issue was that
* the original rect was not being calculated in the same coordinate system that
* PDF.js uses for outline serialization.
*
* In PDF.js, the HighlightEditor.serialize() method calls:
* 1. const rect = this.getRect(0, 0) - to get the rect in page coordinates
* 2. outlines: this.#serializeOutlines(rect) - to serialize outlines using that rect
*
* The #serializeOutlines method then calls:
* return this.#highlightOutlines.serialize(rect, this.#getRotation())
*
* This ensures that the outlines are properly transformed from normalized coordinates
* (0-1 range) to actual page coordinates, taking into account page translation and rotation.
*
* Since we use dontFlip: true in getViewport, the coordinates are already in PDF
* coordinate system (Y=0 at bottom), so we don't need to flip Y coordinates again.
*
* @param {number[]} quadPoints - The quad points of the annotation in page coordinates
* @param {Object} pageDimensions - Page dimensions and translation from viewport.rawDims
* @param {number} rotation - Page rotation in degrees (0, 90, 180, 270)
* @param {boolean} isDontFlip - Whether the viewport was created with dontFlip: true (default: true)
* @returns {number[]} The calculated rect [x1, y1, x2, y2] in page coordinates
*/
export declare const getAnnotationRect: (quadPoints: number[], pageDimensions: {
width: number;
height: number;
pageX: number;
pageY: number;
}, rotation?: number, isDontFlip?: boolean) => number[];