zaynpdf_flutter_pdf 1.1.6 copy "zaynpdf_flutter_pdf: ^1.1.6" to clipboard
zaynpdf_flutter_pdf: ^1.1.6 copied to clipboard

discontinued

Official ZaynPDF Flutter SDK for high-performance PDF manipulation. Edit live text, convert 30+ file formats, compress, merge, split, OCR, watermark & protect PDFs with ease.

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:zaynpdf_flutter_pdf/zaynpdf_flutter_pdf.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // 🔑 Step 1: Register your ZaynPDF API Key globally in main.dart
  ZaynPDF.initialize(
    apiKey: 'zayn_live_9xqv7nx8b86r4u9ddhdwam',
  );

  runApp(const ZaynPdfExampleApp());
}

class ZaynPdfExampleApp extends StatelessWidget {
  const ZaynPdfExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ZaynPDF Flutter SDK Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF6366F1)),
        useMaterial3: true,
      ),
      home: const ZaynPdfHomeScreen(),
    );
  }
}

class ZaynPdfHomeScreen extends StatefulWidget {
  const ZaynPdfHomeScreen({super.key});

  @override
  State<ZaynPdfHomeScreen> createState() => _ZaynPdfHomeScreenState();
}

class _ZaynPdfHomeScreenState extends State<ZaynPdfHomeScreen> {
  bool _isLoading = false;
  String _activeOperation = '';
  String _statusMessage = 'ZaynPDF SDK Initialized & Ready!';

  Future<void> _handleLiveTextEdit() async {
    setState(() {
      _isLoading = true;
      _activeOperation = 'Edit Live Text';
      _statusMessage = 'Replacing text streams directly inside PDF binary...';
    });

    try {
      final samplePdf = File('/path/to/sample_invoice.pdf');

      // âœī¸ Call ZaynPDF Live Text Editor
      final editedPdf = await ZaynPDF.instance.editText(
        pdfFile: samplePdf,
        edits: const [
          PdfTextEdit(find: 'UNPAID', replace: 'PAID IN FULL'),
          PdfTextEdit(find: 'Invoice #100', replace: 'Invoice #2026'),
        ],
      );

      setState(() {
        _statusMessage = '✅ Live Text Edit Successful!\nSaved at: ${editedPdf.path}';
      });
    } catch (e) {
      setState(() {
        _statusMessage = 'â„šī¸ Demo Mode: Real call requires valid file path.\nResult: $e';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  Future<void> _handleConvertFile() async {
    setState(() {
      _isLoading = true;
      _activeOperation = 'Convert to PDF';
      _statusMessage = 'Converting Office/Image document to PDF...';
    });

    try {
      final sampleDoc = File('/path/to/document.docx');

      // 📄 Call ZaynPDF Converter
      final convertedPdf = await ZaynPDF.instance.convertToPdf(
        sourceFile: sampleDoc,
      );

      setState(() {
        _statusMessage = '✅ Document Converted to PDF!\nSaved at: ${convertedPdf.path}';
      });
    } catch (e) {
      setState(() {
        _statusMessage = 'â„šī¸ Demo Mode: Real call requires valid file path.\nResult: $e';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  Future<void> _handleCompressPdf() async {
    setState(() {
      _isLoading = true;
      _activeOperation = 'Compress PDF';
      _statusMessage = 'Optimizing PDF file size by up to 90%...';
    });

    try {
      final samplePdf = File('/path/to/large_document.pdf');

      // ⚡ Call ZaynPDF Compressor
      final compressedPdf = await ZaynPDF.instance.compressPdf(
        pdfFile: samplePdf,
        compressionLevel: 'recommended',
      );

      setState(() {
        _statusMessage = '✅ PDF Compressed Successfully!\nSaved at: ${compressedPdf.path}';
      });
    } catch (e) {
      setState(() {
        _statusMessage = 'â„šī¸ Demo Mode: Real call requires valid file path.\nResult: $e';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  Future<void> _handleProtectPdf() async {
    setState(() {
      _isLoading = true;
      _activeOperation = 'Protect PDF';
      _statusMessage = 'Encrypting PDF with AES-256 password protection...';
    });

    try {
      final samplePdf = File('/path/to/confidential.pdf');

      // 🔒 Call ZaynPDF Encryption
      final protectedPdf = await ZaynPDF.instance.protectPdf(
        pdfFile: samplePdf,
        userPassword: 'SecretPassword123',
      );

      setState(() {
        _statusMessage = '✅ PDF Protected with AES-256!\nSaved at: ${protectedPdf.path}';
      });
    } catch (e) {
      setState(() {
        _statusMessage = 'â„šī¸ Demo Mode: Real call requires valid file path.\nResult: $e';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('ZaynPDF Flutter SDK Demo'),
        centerTitle: true,
        backgroundColor: const Color(0xFF6366F1),
        foregroundColor: Colors.white,
        elevation: 2,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            // API Status Card
            Card(
              elevation: 3,
              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
              child: Padding(
                padding: const EdgeInsets.all(20.0),
                child: Column(
                  children: [
                    Container(
                      padding: const EdgeInsets.all(12),
                      decoration: BoxDecoration(
                        color: const Color(0xFFEEF2FF),
                        shape: BoxShape.circle,
                      ),
                      child: const Icon(
                        Icons.picture_as_pdf_rounded,
                        size: 40,
                        color: Color(0xFF6366F1),
                      ),
                    ),
                    const SizedBox(height: 12),
                    const Text(
                      'ZaynPDF.initialize(apiKey: "zayn_live_...")',
                      style: TextStyle(
                        fontFamily: 'monospace',
                        fontSize: 12,
                        color: Color(0xFF4F46E5),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    const SizedBox(height: 12),
                    Text(
                      _statusMessage,
                      textAlign: TextAlign.center,
                      style: const TextStyle(
                        fontSize: 14,
                        fontWeight: FontWeight.w600,
                        color: Color(0xFF1F2937),
                      ),
                    ),
                    if (_isLoading) ...[
                      const SizedBox(height: 16),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          const SizedBox(
                            width: 18,
                            height: 18,
                            child: CircularProgressIndicator(strokeWidth: 2.5),
                          ),
                          const SizedBox(width: 10),
                          Text(
                            'Processing $_activeOperation...',
                            style: const TextStyle(
                              fontSize: 13,
                              color: Color(0xFF6B7280),
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ],
                      ),
                    ],
                  ],
                ),
              ),
            ),
            const SizedBox(height: 24),
            const Text(
              'SDK FEATURE DEMOS',
              style: TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.w800,
                color: Color(0xFF9CA3AF),
                letterSpacing: 1.1,
              ),
            ),
            const SizedBox(height: 12),

            // Action Buttons
            _buildActionButton(
              icon: Icons.edit_note_rounded,
              label: '1. Edit Live Text (Core Engine)',
              subtitle: 'Replace words directly in PDF binary stream',
              color: const Color(0xFF6366F1),
              onPressed: _isLoading ? null : _handleLiveTextEdit,
            ),
            const SizedBox(height: 10),
            _buildActionButton(
              icon: Icons.transform_rounded,
              label: '2. Convert 30+ Formats to PDF',
              subtitle: 'Word, Excel, Images, eBooks directly to PDF',
              color: const Color(0xFF10B981),
              onPressed: _isLoading ? null : _handleConvertFile,
            ),
            const SizedBox(height: 10),
            _buildActionButton(
              icon: Icons.compress_rounded,
              label: '3. Compress PDF (Up to 90%)',
              subtitle: 'Optimize PDF size without losing quality',
              color: const Color(0xFFF59E0B),
              onPressed: _isLoading ? null : _handleCompressPdf,
            ),
            const SizedBox(height: 10),
            _buildActionButton(
              icon: Icons.lock_outline_rounded,
              label: '4. Protect & Encrypt PDF',
              subtitle: 'AES-256 password & permissions security',
              color: const Color(0xFFEC4899),
              onPressed: _isLoading ? null : _handleProtectPdf,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildActionButton({
    required IconData icon,
    required String label,
    required String subtitle,
    required Color color,
    required VoidCallback? onPressed,
  }) {
    return ElevatedButton(
      onPressed: onPressed,
      style: ElevatedButton.styleFrom(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
        elevation: 1,
        backgroundColor: Colors.white,
        foregroundColor: const Color(0xFF1F2937),
        surfaceTintColor: Colors.transparent,
        side: const BorderSide(color: Color(0xFFE5E7EB)),
      ),
      child: Row(
        children: [
          Container(
            padding: const EdgeInsets.all(10),
            decoration: BoxDecoration(
              color: color.withValues(alpha: 0.1),
              borderRadius: BorderRadius.circular(10),
            ),
            child: Icon(icon, color: color, size: 24),
          ),
          const SizedBox(width: 14),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  label,
                  style: const TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.bold,
                    color: Color(0xFF1F2937),
                  ),
                ),
                const SizedBox(height: 2),
                Text(
                  subtitle,
                  style: const TextStyle(
                    fontSize: 12,
                    color: Color(0xFF6B7280),
                  ),
                ),
              ],
            ),
          ),
          const Icon(Icons.chevron_right_rounded, color: Color(0xFF9CA3AF)),
        ],
      ),
    );
  }
}
0
likes
160
points
51
downloads

Documentation

API reference

Publisher

verified publisherbalochcodes.com

Weekly Downloads

Official ZaynPDF Flutter SDK for high-performance PDF manipulation. Edit live text, convert 30+ file formats, compress, merge, split, OCR, watermark & protect PDFs with ease.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, http, path_provider, syncfusion_flutter_pdfviewer

More

Packages that depend on zaynpdf_flutter_pdf