@@ -56,6 +56,14 @@ public class PdfViewer extends Div {
56
56
private boolean addPrintButton = false ;
57
57
private Button printButton ;
58
58
59
+ /* Indicates if Rotate Clockwise button is added to toolbar or not */
60
+ private boolean addRotateClockwiseButton = false ;
61
+ private Button rotateClockwiseButton ;
62
+
63
+ /* Indicates if Rotate Counterclockwise button is added to toolbar or not */
64
+ private boolean addRotateCounterClockwiseButton = false ;
65
+ private Button rotateCounterClockwiseButton ;
66
+
59
67
public PdfViewer () {}
60
68
61
69
/**
@@ -266,6 +274,46 @@ public void setRenderInteractiveForms(boolean renderInteractiveForms) {
266
274
public void hideZoom (boolean hideZoom ) {
267
275
this .getElement ().setProperty ("hideZoom" , hideZoom );
268
276
}
277
+
278
+ /**
279
+ * Returns whether Rotate Clockwise button is added to the toolbar or not.
280
+ *
281
+ * @return true if the button is added to toolbar
282
+ */
283
+ public boolean isAddRotateClockwiseButton () {
284
+ return addRotateClockwiseButton ;
285
+ }
286
+
287
+ /**
288
+ * <p>Sets the flag to indicate if Rotate Clockwise button should be added to toolbar or not.
289
+ * By default the flag is set to false, so, by default the button is not added to the toolbar. </p>
290
+ * <p>This flag should be set on pdf viewer initialization time.</p>
291
+ *
292
+ * @param addRotateClockwiseButton true if rotate clockwise button should be added to toolbar
293
+ */
294
+ public void setAddRotateClockwiseButton (boolean addRotateClockwiseButton ) {
295
+ this .addRotateClockwiseButton = addRotateClockwiseButton ;
296
+ }
297
+
298
+ /**
299
+ * Returns whether Rotate Counterclockwise button is added to the toolbar or not.
300
+ *
301
+ * @return true if the button is added to toolbar
302
+ */
303
+ public boolean isAddRotateCounterClockwiseButton () {
304
+ return addRotateCounterClockwiseButton ;
305
+ }
306
+
307
+ /**
308
+ * <p>Sets the flag to indicate if Rotate Counterclockwise button should be added to toolbar or not.
309
+ * By default the flag is set to false, so, by default the button is not added to the toolbar. </p>
310
+ * <p>This flag should be set on pdf viewer initialization time.</p>
311
+ *
312
+ * @param addRotateCounterClockwiseButton true if rotate counterclockwise button should be added to toolbar
313
+ */
314
+ public void setAddRotateCounterClockwiseButton (boolean addRotateCounterClockwiseButton ) {
315
+ this .addRotateCounterClockwiseButton = addRotateCounterClockwiseButton ;
316
+ }
269
317
270
318
@ Override
271
319
protected void onAttach (AttachEvent attachEvent ) {
@@ -276,6 +324,12 @@ protected void onAttach(AttachEvent attachEvent) {
276
324
if (addPrintButton ){
277
325
addPrintButton ();
278
326
}
327
+ if (addRotateClockwiseButton ){
328
+ addRotateClockwiseButton ();
329
+ }
330
+ if (addRotateCounterClockwiseButton ){
331
+ addRotateCounterClockwiseButton ();
332
+ }
279
333
}
280
334
281
335
@ Override
@@ -287,6 +341,12 @@ protected void onDetach(DetachEvent detachEvent) {
287
341
if (addPrintButton ){
288
342
this .getElement ().removeChild (printButton .getElement ());
289
343
}
344
+ if (addRotateClockwiseButton ){
345
+ this .getElement ().removeChild (rotateClockwiseButton .getElement ());
346
+ }
347
+ if (addRotateCounterClockwiseButton ){
348
+ this .getElement ().removeChild (rotateCounterClockwiseButton .getElement ());
349
+ }
290
350
}
291
351
292
352
/**
@@ -333,4 +393,26 @@ private void addPrintButton() {
333
393
printButton .addClickListener (e -> this .getElement ().executeJs ("printPdf.printPdf($0)" , this .getSrc ()));
334
394
}
335
395
396
+ /**
397
+ * Adds button to rotate pdf file clockwise.
398
+ */
399
+ private void addRotateClockwiseButton () {
400
+ rotateClockwiseButton = new Button (new Icon (VaadinIcon .ROTATE_RIGHT ));
401
+ rotateClockwiseButton .getElement ().setAttribute ("aria-label" , "Rotate clockwise" );
402
+ rotateClockwiseButton .setThemeName ("rotate-button" );
403
+ getElement ().appendChild (rotateClockwiseButton .getElement ());
404
+ rotateClockwiseButton .addClickListener (e -> this .getElement ().executeJs ("this.rotateCw()" ));
405
+ }
406
+
407
+ /**
408
+ * Adds button to rotate pdf file counterclockwise.
409
+ */
410
+ private void addRotateCounterClockwiseButton () {
411
+ rotateCounterClockwiseButton = new Button (new Icon (VaadinIcon .ROTATE_LEFT ));
412
+ rotateCounterClockwiseButton .getElement ().setAttribute ("aria-label" , "Rotate counterclockwise" );
413
+ rotateCounterClockwiseButton .setThemeName ("rotate-button" );
414
+ getElement ().appendChild (rotateCounterClockwiseButton .getElement ());
415
+ rotateCounterClockwiseButton .addClickListener (e -> this .getElement ().executeJs ("this.rotateCcw()" ));
416
+ }
417
+
336
418
}
0 commit comments