PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
ComPDF SDK for Flutter offers multiple ways to open PDF documents depending on your use case:
CPDFReaderWidget to display an embedded reader UI.ComPDFKit.openDocument() to quickly launch a full-screen document viewer.CPDFDocument for background processing or non-UI operations.Using CPDFReaderWidget (Recommended for embedded reader scenarios)
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) {
},))Using ComPDFKit.openDocument() (Quick full-screen viewer)
This is ideal for quickly launching a standalone document viewer.
const String _documentPath = 'pdfs/PDF_Document.pdf';
File document = await CPDFFileUtil.extractAsset(_documentPath);
ComPDFKit.openDocument(document.path, password: '', configuration: CPDFConfiguration());Using CPDFDocument (For background or logic-only use cases)
This is useful for non-UI operations such as annotation management, import/export, etc.
const String _documentPath = 'pdfs/PDF_Document.pdf';
File sourceFile = await CPDFFileUtil.extractAsset(_documentPath);
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
CPDFDocumentError error = await document.open(sourceFile.path);
if (error == CPDFDocumentError.success) {
// Perform operations with the CPDFDocument instance...
}Starting with 3.2.0, CPDFReaderWidget retains the original path when opening a file in the application sandbox. Subsequent edits and saves apply to that file. Resources in the application bundle are still copied to a writable directory before opening.
To retain the original, create a working copy first or use Save As.