Cloud
Облачный сервис для быстрого и эффективного анализа и визуализации данных для вашего бизнеса без необходимости создания своих приложений и программирования.
StimulsoftViewerHandle and attach it to the component. Through that handle you get access to the viewer's properties and methods:import React, { useRef, useState, useEffect } from 'react';
import { StimulsoftViewer, StimulsoftViewerHandle } from 'stimulsoft-viewer-react';
export const App: React.FC = () => {
const viewerRef = useRef<StimulsoftViewerHandle>(null);
const [zoom, setZoom] = useState<number>(100);
const [currentPage, setCurrentPage] = useState<number>(0);
// Poll the viewer state and mirror it into React state
useEffect(() => {
const interval = setInterval(() => {
if (viewerRef.current) {
setZoom(viewerRef.current.zoom);
setCurrentPage(viewerRef.current.currentPage);
}
}, 200);
return () => clearInterval(interval);
}, []);
return (
<div>
Zoom is {zoom}<br />
Current page {currentPage + 1}<br />
<input type="button" value="Zoom to 50%"
onClick={() => { if (viewerRef.current) viewerRef.current.zoom = 50; }} />
<input type="button" value="Export to PDF"
onClick={() => { if (viewerRef.current) viewerRef.current.export('Pdf', { ImageResolution: 200 }); }} />
<StimulsoftViewer ref={viewerRef} requestUrl="/Viewer/{action}" action="InitViewer" height="100vh" />
</div>
);
};The key parts of the API used here:viewerRef.current.zoom — reads or sets the zoom level in percent; assigning 50 zooms the report to 50%.viewerRef.current.currentPage — the zero-based index of the page the user is viewing (shown as + 1 for a human-friendly number).viewerRef.current.export('Pdf', { ImageResolution: 200 }) — exports the report to a given format with export settings; here PDF at 200 DPI.