PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
旋转指定页面的显示方向,支持 90 度顺时针和逆时针旋转。
使用 CPDFReaderWidget:
CPDFReaderWidgetController? _controller;
// 初始化 CPDFReaderWidget,并在 onCreated 回调中获取 controller
CPDFReaderWidget(
document: documentPath,
configuration: CPDFConfiguration(),
onCreated: (controller) {
setState(() {
this._controller = controller;
});
},
);
// 旋转第一页页面
const pageIndex = 0;
final page = controller.document.pageAtIndex(pageIndex);
final currentRotation = await page.getRotation();
final newAngle = currentRotation + 90;
final result = await page.setRotation(newAngle);
// 成功后刷新页面
if (result) {
controller.reloadPages();
}使用 CPDFDocument:
// 创建并打开文档
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
// 旋转第一页页面
const pageIndex = 0;
final page = document.pageAtIndex(pageIndex);
final currentRotation = await page.getRotation();
final newAngle = currentRotation + 90;
final result = await page.setRotation(newAngle);
}