Rotation
The PDFViewer includes built-in support for rotating documents in 90-degree increments. While the default toolbar includes rotation buttons (in the page settings menu), you may want to build custom controls or trigger rotation programmatically.
Programmatic Control
You can control rotation using the rotate plugin API. This allows you to build custom toolbars or keyboard shortcuts.
Rotating the Active Document
To rotate whatever document is currently visible:
const registry = await viewerRef.current?.registry;
const rotate = registry.getPlugin('rotate').provides();
// Rotate 90 degrees clockwise
rotate.rotateForward();
// Rotate 90 degrees counter-clockwise
rotate.rotateBackward();Rotating a Specific Document
To target a specific document (e.g., ‘invoice-123’) regardless of whether it’s active:
const docRotate = rotate.forDocument('invoice-123');
// Set specific rotation (0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°)
docRotate.setRotation(2); Listening for Changes
You can listen for rotation changes to keep your external UI in sync.
const registry = await viewerRef.current?.registry;
const rotate = registry.getPlugin('rotate').provides();
// Subscribe to global rotation changes (any document)
rotate.onRotateChange(({ documentId, rotation }) => {
console.log(`Document ${documentId} rotated to ${rotation * 90}°`);
});
// Or subscribe to a specific document
const docRotate = rotate.forDocument('my-doc');
docRotate.onRotateChange((rotation) => {
console.log(`My doc is now at ${rotation * 90}°`);
});Last updated on December 28, 2025
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.