ares_defence_labs_lock_smith_pdf 0.0.7 copy "ares_defence_labs_lock_smith_pdf: ^0.0.7" to clipboard
ares_defence_labs_lock_smith_pdf: ^0.0.7 copied to clipboard

A Flutter plugin for password-protecting PDFs with 256-bit encryption. Add a password for encryption, permissions management and decrypting a PDF

example/lib/main.dart

import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:ares_defence_labs_lock_smith_pdf/ares_defence_labs_lock_smith_pdf.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Future<String> getPdfFilePath(String fileName) async {
    final Directory appDir = await getApplicationDocumentsDirectory();

    // Ensure the file has .pdf extension
    final safeFileName = fileName.endsWith('.pdf') ? fileName : '$fileName.pdf';

    final String filePath = '${appDir.path}/$safeFileName';

    return filePath;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Column(
          children: [
            MaterialButton(
              child: Text("Encrypt PDF"),
              onPressed: () async {
                var pickedFile = await FilePicker.platform.pickFiles();
                if (pickedFile != null) {
                  var output = await getPdfFilePath("random_test");

                  await AresDefenceLabsLocksmithPdf.protectPdf(
                    inputPath: pickedFile.files.first.path!,
                    outputPath: output,
                    password: "secretPassword123",
                  ).then((e) async {
                    print(
                      "IS ENCRYPTED : ${await AresDefenceLabsLocksmithPdf.isPdfEncrypted(inputPath: output)}",
                    );
                    final params = ShareParams(
                      text: 'Sample PDF',
                      files: [XFile(output)],
                    );

                    final result = await SharePlus.instance.share(params);
                  });
                }
              },
            ),
            MaterialButton(
              child: Text("Encrypt PDF with Permissions"),
              onPressed: () async {
                var pickedFile = await FilePicker.platform.pickFiles();
                if (pickedFile != null) {
                  var output = await getPdfFilePath("random_test");

                  await AresDefenceLabsLocksmithPdf.protectPdfWithPermissions(
                    inputPath: pickedFile.files.first.path!,
                    outputPath: output,
                    userPassword: "secretPassword123",
                    ownerPassword: "permissionPassword",
                    permissions: [
                      PermissionOption.fillForms,
                      PermissionOption.modify,
                    ],
                  ).then((e) async {
                    final params = ShareParams(
                      text: 'Sample PDF',
                      files: [XFile(output)],
                    );

                    final result = await SharePlus.instance.share(params);
                  });
                }
              },
            ),
            MaterialButton(
              child: Text("Decrypt PDF"),
              onPressed: () async {
                var pickedFile = await FilePicker.platform.pickFiles();
                if (pickedFile != null) {
                  var output = await getPdfFilePath("random_test");

                  await AresDefenceLabsLocksmithPdf.decryptPdf(
                    inputPath: pickedFile.files.first.path!,
                    outputPath: output,
                    password: "",
                  ).then((e) async {
                    final params = ShareParams(
                      text: 'Sample PDF',
                      files: [XFile(output)],
                    );

                    final result = await SharePlus.instance.share(params);
                  });
                }
              },
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
160
points
48
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for password-protecting PDFs with 256-bit encryption. Add a password for encryption, permissions management and decrypting a PDF

Repository (GitHub)

Topics

#pdf #encryption #security #password #android

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on ares_defence_labs_lock_smith_pdf