@@ -1554,6 +1554,9 @@ class PDFViewer {
15541554 * The default value is `false`.
15551555 * @property {boolean } [ignoreDestinationZoom] - Ignore the zoom argument in
15561556 * the destination array. The default value is `false`.
1557+ * @property {string } [center] - Center the view on the specified coordinates.
1558+ * The default value is `null`. Possible values are: `null` (don't center),
1559+ * `horizontal`, `vertical` and `both`.
15571560 */
15581561
15591562 /**
@@ -1565,6 +1568,7 @@ class PDFViewer {
15651568 destArray = null ,
15661569 allowNegativeOffset = false ,
15671570 ignoreDestinationZoom = false ,
1571+ center = null ,
15681572 } ) {
15691573 if ( ! this . pdfDocument ) {
15701574 return ;
@@ -1687,7 +1691,20 @@ class PDFViewer {
16871691 let left = Math . min ( boundingRect [ 0 ] [ 0 ] , boundingRect [ 1 ] [ 0 ] ) ;
16881692 let top = Math . min ( boundingRect [ 0 ] [ 1 ] , boundingRect [ 1 ] [ 1 ] ) ;
16891693
1690- if ( ! allowNegativeOffset ) {
1694+ if ( center ) {
1695+ if ( center === "both" || center === "vertical" ) {
1696+ top -=
1697+ ( this . container . clientHeight -
1698+ Math . abs ( boundingRect [ 1 ] [ 1 ] - boundingRect [ 0 ] [ 1 ] ) ) /
1699+ 2 ;
1700+ }
1701+ if ( center === "both" || center === "horizontal" ) {
1702+ left -=
1703+ ( this . container . clientWidth -
1704+ Math . abs ( boundingRect [ 1 ] [ 0 ] - boundingRect [ 0 ] [ 0 ] ) ) /
1705+ 2 ;
1706+ }
1707+ } else if ( ! allowNegativeOffset ) {
16911708 // Some bad PDF generators will create destinations with e.g. top values
16921709 // that exceeds the page height. Ensure that offsets are not negative,
16931710 // to prevent a previous page from becoming visible (fixes bug 874482).
0 commit comments