diff --git a/.flutter-plugins b/.flutter-plugins index 25d95e7..0fc73ae 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -13,3 +13,5 @@ path_provider_linux=/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_linux- path_provider_windows=/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.3/ pdfx=/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/ printing=/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/ +screen_retriever=/home/naoufal/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/ +window_manager=/home/naoufal/.pub-cache/hosted/pub.dev/window_manager-0.3.0/ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 9a638d4..5029ce4 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus-4.1.3/","native_build":true,"dependencies":[]},{"name":"file_picker","path":"/home/naoufal/.pub-cache/hosted/pub.dev/file_picker-5.2.5/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_foundation-2.1.1/","native_build":true,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":["device_info_plus"]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus-4.1.3/","native_build":true,"dependencies":[]},{"name":"file_picker","path":"/home/naoufal/.pub-cache/hosted/pub.dev/file_picker-5.2.5/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/home/naoufal/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.7/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_android-2.0.22/","native_build":true,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":["device_info_plus"]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus_macos","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_macos-3.0.0/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_foundation-2.1.1/","native_build":true,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus_linux","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_linux-3.0.0/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.8/","native_build":false,"dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"windows":[{"name":"device_info_plus_windows","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_windows-4.1.0/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.3/","native_build":false,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"web":[{"name":"device_info_plus_web","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_web-3.0.0/","dependencies":[]},{"name":"file_picker","path":"/home/naoufal/.pub-cache/hosted/pub.dev/file_picker-5.2.5/","dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":["device_info_plus_macos","device_info_plus_linux","device_info_plus_web","device_info_plus_windows"]},{"name":"device_info_plus_linux","dependencies":[]},{"name":"device_info_plus_macos","dependencies":[]},{"name":"device_info_plus_web","dependencies":[]},{"name":"device_info_plus_windows","dependencies":[]},{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"pdfx","dependencies":["device_info_plus"]},{"name":"printing","dependencies":[]}],"date_created":"2023-02-23 15:50:44.341611","version":"3.7.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus-4.1.3/","native_build":true,"dependencies":[]},{"name":"file_picker","path":"/home/naoufal/.pub-cache/hosted/pub.dev/file_picker-5.2.5/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_foundation-2.1.1/","native_build":true,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":["device_info_plus"]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus-4.1.3/","native_build":true,"dependencies":[]},{"name":"file_picker","path":"/home/naoufal/.pub-cache/hosted/pub.dev/file_picker-5.2.5/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/home/naoufal/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.7/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_android-2.0.22/","native_build":true,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":["device_info_plus"]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus_macos","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_macos-3.0.0/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_foundation-2.1.1/","native_build":true,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]},{"name":"screen_retriever","path":"/home/naoufal/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/","native_build":true,"dependencies":[]},{"name":"window_manager","path":"/home/naoufal/.pub-cache/hosted/pub.dev/window_manager-0.3.0/","native_build":true,"dependencies":["screen_retriever"]}],"linux":[{"name":"device_info_plus_linux","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_linux-3.0.0/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.8/","native_build":false,"dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]},{"name":"screen_retriever","path":"/home/naoufal/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/","native_build":true,"dependencies":[]},{"name":"window_manager","path":"/home/naoufal/.pub-cache/hosted/pub.dev/window_manager-0.3.0/","native_build":true,"dependencies":["screen_retriever"]}],"windows":[{"name":"device_info_plus_windows","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_windows-4.1.0/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.3/","native_build":false,"dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","native_build":true,"dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","native_build":true,"dependencies":[]},{"name":"screen_retriever","path":"/home/naoufal/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/","native_build":true,"dependencies":[]},{"name":"window_manager","path":"/home/naoufal/.pub-cache/hosted/pub.dev/window_manager-0.3.0/","native_build":true,"dependencies":["screen_retriever"]}],"web":[{"name":"device_info_plus_web","path":"/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_web-3.0.0/","dependencies":[]},{"name":"file_picker","path":"/home/naoufal/.pub-cache/hosted/pub.dev/file_picker-5.2.5/","dependencies":[]},{"name":"pdfx","path":"/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/","dependencies":[]},{"name":"printing","path":"/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":["device_info_plus_macos","device_info_plus_linux","device_info_plus_web","device_info_plus_windows"]},{"name":"device_info_plus_linux","dependencies":[]},{"name":"device_info_plus_macos","dependencies":[]},{"name":"device_info_plus_web","dependencies":[]},{"name":"device_info_plus_windows","dependencies":[]},{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"pdfx","dependencies":["device_info_plus"]},{"name":"printing","dependencies":[]},{"name":"screen_retriever","dependencies":[]},{"name":"window_manager","dependencies":["screen_retriever"]}],"date_created":"2023-02-25 14:39:42.635250","version":"3.7.3"} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 743fa4d..bffed06 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,28 +6,41 @@ import 'package:flutter/services.dart'; import 'package:pdf/pdf.dart'; import 'package:printing/printing.dart'; import 'package:pdf/widgets.dart' as pw; +import 'package:window_manager/window_manager.dart'; Future main() async { - runApp(MyApp('PDF Tools')); + WidgetsFlutterBinding.ensureInitialized(); + // Must add this line. + await windowManager.ensureInitialized(); + if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { + await windowManager.setSize(const Size(450, 300)); + } + runApp(const MyApp()); } // ignore: must_be_immutable -class MyApp extends StatelessWidget { - MyApp(this.title, {Key? key}) : super(key: key); - final String title; - String openFilePath = ""; - double dpi = 200; +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + String _openFilePath = ""; + String? _encryption = ""; + double _dpi = 200; Future convert(String savePath) async { final pdf = pw.Document(); final file = File(savePath); - final openddPdf = await rootBundle.load(openFilePath); + final openddPdf = await rootBundle.load(_openFilePath); var doc = openddPdf.buffer.asUint8List(); // var tempDir = Directory.systemTemp.createTempSync(); // int index = 1; - await for (var page in Printing.raster(doc, dpi: dpi)) { + await for (var page in Printing.raster(doc, dpi: _dpi)) { final image = await page.toImage(); final data = await image.toByteData(format: ui.ImageByteFormat.png); @@ -42,6 +55,7 @@ class MyApp extends StatelessWidget { // index++; } + return file.writeAsBytes(await pdf.save()); } @@ -49,17 +63,19 @@ class MyApp extends StatelessWidget { FilePickerResult? result = await FilePicker.platform .pickFiles(allowMultiple: false, lockParentWindow: true); if (result != null) { - openFilePath = result.files.first.path!; + setState(() { + _openFilePath = result.files.first.path!; + }); } else { // User canceled the picker } } - void saveFile() async { + Future saveFile() async { var savePath = await FilePicker.platform .saveFile(allowedExtensions: ['pdf'], lockParentWindow: true); if (savePath != null) { - convert(savePath); + return await convert(savePath); } else { // User canceled the picker } @@ -70,15 +86,83 @@ class MyApp extends StatelessWidget { // test(); return MaterialApp( home: Scaffold( - appBar: AppBar(title: Text(title)), - body: Column( - children: [ - const Text("data"), - ElevatedButton( - onPressed: () => openFile(), child: const Text("open")), - ElevatedButton( - onPressed: () => saveFile(), child: const Text("save")), - ], + appBar: AppBar(title: const Text("PDF Tools")), + body: SizedBox( + width: double.infinity, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + children: [ + Text(_openFilePath), + Column(children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisSize: MainAxisSize.max, + children: [ + const Text("Quality :"), + Expanded( + child: Slider( + min: 100, + max: 500, + divisions: 20, + label: _dpi.toString(), + value: _dpi, + onChanged: (value) { + setState(() { + _dpi = value; + }); + }, + ), + ), + Text(_dpi.toString()), + ], + ), + const SizedBox(height: 10), + TextField( + decoration: const InputDecoration( + labelText: 'Encrypt (Optional)', + border: OutlineInputBorder(), + ), + controller: TextEditingController(text: _encryption), + onSubmitted: (value) { + setState(() { + _encryption = value; + }); + }, + ), + const SizedBox(height: 10), + Row( + children: [ + ElevatedButton( + onPressed: () => openFile(), + child: Flex( + direction: Axis.vertical, + children: const [ + Icon(Icons.folder), + Text("Open pdf") + ], + )), + ElevatedButton( + onPressed: () async { + await saveFile(); + showDialog( + context: context, + builder: (context) => Text("ok"), + ); + }, + child: Flex( + direction: Axis.vertical, + children: const [ + Icon(Icons.save), + Text("save"), + ], + )), + ], + ), + ]) + ], + ), + ), ), ), ); diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index ce0e550..af59b2e 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -7,9 +7,17 @@ #include "generated_plugin_registrant.h" #include +#include +#include void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) printing_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin"); printing_plugin_register_with_registrar(printing_registrar); + g_autoptr(FlPluginRegistrar) screen_retriever_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); + screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); + g_autoptr(FlPluginRegistrar) window_manager_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin"); + window_manager_plugin_register_with_registrar(window_manager_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 0c2c3c3..512628d 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -4,6 +4,8 @@ list(APPEND FLUTTER_PLUGIN_LIST printing + screen_retriever + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 1701f6b..a690f34 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -9,10 +9,14 @@ import device_info_plus_macos import path_provider_foundation import pdfx import printing +import screen_retriever +import window_manager func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin")) PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin")) + ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) + WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) } diff --git a/pp b/pp new file mode 100644 index 0000000..9ee8c9e Binary files /dev/null and b/pp differ diff --git a/pubspec.yaml b/pubspec.yaml index d4f2ff6..84bd6f0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,9 @@ dependencies: path_provider: ^2.0.12 pdfx: ^2.3.0 printing: ^5.10.1 + window_manager: ^0.3.0 + flutter_localizations: + sdk: flutter dev_dependencies: flutter_test: diff --git a/tt b/tt new file mode 100644 index 0000000..772d94a Binary files /dev/null and b/tt differ diff --git a/tt.pdf b/tt.pdf new file mode 100644 index 0000000..9fba5f2 Binary files /dev/null and b/tt.pdf differ diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 7670fc1..c1a224e 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -8,10 +8,16 @@ #include #include +#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { PdfxPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PdfxPlugin")); PrintingPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PrintingPlugin")); + ScreenRetrieverPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); + WindowManagerPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("WindowManagerPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 3d65c52..bcb3de9 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -5,6 +5,8 @@ list(APPEND FLUTTER_PLUGIN_LIST pdfx printing + screen_retriever + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST