Skip to content
ComPDF
Guides

旋转页面

旋转指定页面的显示方向,支持以 90 度为单位进行顺时针或逆时针旋转。

以下示例演示如何旋转页面:

tsx
const pdfReaderRef = useRef<CPDFReaderView>(null);

<CPDFReaderView
  ref={pdfReaderRef}
  document={samplePDF}
  configuration={ComPDFKit.getDefaultConfig({})}
/>

// 获取页面当前旋转角度
const pageIndex = 0;
const page = await pdfReaderRef.current?._pdfDocument.pageAtIndex(pageIndex);
const rotation = await page?.getRotation();

// 设置新的旋转角度(在当前角度基础上顺时针旋转 90 度)
const result = await page?.setRotation(rotation! + 90);
if (result) {
  // 刷新页面以应用旋转效果
  await pdfReaderRef.current?.reloadPages();
}