PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
ComPDF SDK for Flutter 提供多种方式打开 PDF 文档,适用于不同使用场景:
CPDFReaderWidget 显示内嵌阅读器 UI。ComPDFKit.openDocument() 直接启动完整文档视图。 CPDFDocument 进行后台处理或无 UI 操作。使用 CPDFReaderWidget(推荐内嵌阅读场景)
const String _documentPath = 'pdfs/PDF_Document.pdf';
File document = await CPDFFileUtil.extractAsset(_documentPath, shouldOverwrite: false);
Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(),
body: CPDFReaderWidget(
document: document.path,
configuration: CPDFConfiguration(),
onCreated: (controller) {
},))使用 ComPDFKit.openDocument()(快速跳转阅读器界面)
适合直接打开一个新的阅读界面,快速预览 PDF 文件。
const String _documentPath = 'pdfs/PDF_Document.pdf';
File document = await CPDFFileUtil.extractAsset(_documentPath);
ComPDFKit.openDocument(document.path, password: '', configuration: CPDFConfiguration());使用 CPDFDocument(后台处理场景)
适合不需要 UI 的场景,例如文档注释操作、导出导入等。
const String _documentPath = 'pdfs/PDF_Document.pdf';
File sourceFile = await CPDFFileUtil.extractAsset(_documentPath);
// 创建并打开文档
CPDFDocument document = await CPDFDocument.createInstance();
CPDFDocumentError error = await document.open(sourceFile.path);
if (error == CPDFDocumentError.success) {
// 使用CPDFDocument对象进行其他操作...
}自 3.2.0 起,CPDFReaderWidget 打开应用沙盒内的文件时保留原文件路径,后续编辑和保存作用于该文件。应用包内的资源文件仍会复制到可写目录后打开。
需要保留原文件时,应先创建工作副本,或使用另存为。