mirror of
https://github.com/naoufalzerai/pdf_tools.git
synced 2025-11-09 07:45:54 +00:00
todo safeguard
This commit is contained in:
parent
6a7de1fc3d
commit
7af41bcf45
@ -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/
|
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/
|
pdfx=/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/
|
||||||
printing=/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/
|
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/
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
120
lib/main.dart
120
lib/main.dart
@ -6,28 +6,41 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:pdf/pdf.dart';
|
import 'package:pdf/pdf.dart';
|
||||||
import 'package:printing/printing.dart';
|
import 'package:printing/printing.dart';
|
||||||
import 'package:pdf/widgets.dart' as pw;
|
import 'package:pdf/widgets.dart' as pw;
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> 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
|
// ignore: must_be_immutable
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatefulWidget {
|
||||||
MyApp(this.title, {Key? key}) : super(key: key);
|
const MyApp({super.key});
|
||||||
final String title;
|
|
||||||
String openFilePath = "";
|
@override
|
||||||
double dpi = 200;
|
State<MyApp> createState() => _MyAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MyAppState extends State<MyApp> {
|
||||||
|
String _openFilePath = "";
|
||||||
|
String? _encryption = "";
|
||||||
|
double _dpi = 200;
|
||||||
Future convert(String savePath) async {
|
Future convert(String savePath) async {
|
||||||
final pdf = pw.Document();
|
final pdf = pw.Document();
|
||||||
final file = File(savePath);
|
final file = File(savePath);
|
||||||
|
|
||||||
final openddPdf = await rootBundle.load(openFilePath);
|
final openddPdf = await rootBundle.load(_openFilePath);
|
||||||
var doc = openddPdf.buffer.asUint8List();
|
var doc = openddPdf.buffer.asUint8List();
|
||||||
|
|
||||||
// var tempDir = Directory.systemTemp.createTempSync();
|
// var tempDir = Directory.systemTemp.createTempSync();
|
||||||
// int index = 1;
|
// 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 image = await page.toImage();
|
||||||
final data = await image.toByteData(format: ui.ImageByteFormat.png);
|
final data = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||||
|
|
||||||
@ -42,6 +55,7 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
// index++;
|
// index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return file.writeAsBytes(await pdf.save());
|
return file.writeAsBytes(await pdf.save());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,17 +63,19 @@ class MyApp extends StatelessWidget {
|
|||||||
FilePickerResult? result = await FilePicker.platform
|
FilePickerResult? result = await FilePicker.platform
|
||||||
.pickFiles(allowMultiple: false, lockParentWindow: true);
|
.pickFiles(allowMultiple: false, lockParentWindow: true);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
openFilePath = result.files.first.path!;
|
setState(() {
|
||||||
|
_openFilePath = result.files.first.path!;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// User canceled the picker
|
// User canceled the picker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveFile() async {
|
Future saveFile() async {
|
||||||
var savePath = await FilePicker.platform
|
var savePath = await FilePicker.platform
|
||||||
.saveFile(allowedExtensions: ['pdf'], lockParentWindow: true);
|
.saveFile(allowedExtensions: ['pdf'], lockParentWindow: true);
|
||||||
if (savePath != null) {
|
if (savePath != null) {
|
||||||
convert(savePath);
|
return await convert(savePath);
|
||||||
} else {
|
} else {
|
||||||
// User canceled the picker
|
// User canceled the picker
|
||||||
}
|
}
|
||||||
@ -70,16 +86,84 @@ class MyApp extends StatelessWidget {
|
|||||||
// test();
|
// test();
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
appBar: AppBar(title: Text(title)),
|
appBar: AppBar(title: const Text("PDF Tools")),
|
||||||
body: Column(
|
body: SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const Text("data"),
|
Text(_openFilePath),
|
||||||
ElevatedButton(
|
Column(children: [
|
||||||
onPressed: () => openFile(), child: const Text("open")),
|
Row(
|
||||||
ElevatedButton(
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
onPressed: () => saveFile(), child: const Text("save")),
|
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"),
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
])
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,17 @@
|
|||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <printing/printing_plugin.h>
|
#include <printing/printing_plugin.h>
|
||||||
|
#include <screen_retriever/screen_retriever_plugin.h>
|
||||||
|
#include <window_manager/window_manager_plugin.h>
|
||||||
|
|
||||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||||
g_autoptr(FlPluginRegistrar) printing_registrar =
|
g_autoptr(FlPluginRegistrar) printing_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin");
|
||||||
printing_plugin_register_with_registrar(printing_registrar);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
printing
|
printing
|
||||||
|
screen_retriever
|
||||||
|
window_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
|||||||
@ -9,10 +9,14 @@ import device_info_plus_macos
|
|||||||
import path_provider_foundation
|
import path_provider_foundation
|
||||||
import pdfx
|
import pdfx
|
||||||
import printing
|
import printing
|
||||||
|
import screen_retriever
|
||||||
|
import window_manager
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin"))
|
PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin"))
|
||||||
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
|
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
|
||||||
|
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
|
||||||
|
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,9 @@ dependencies:
|
|||||||
path_provider: ^2.0.12
|
path_provider: ^2.0.12
|
||||||
pdfx: ^2.3.0
|
pdfx: ^2.3.0
|
||||||
printing: ^5.10.1
|
printing: ^5.10.1
|
||||||
|
window_manager: ^0.3.0
|
||||||
|
flutter_localizations:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@ -8,10 +8,16 @@
|
|||||||
|
|
||||||
#include <pdfx/pdfx_plugin.h>
|
#include <pdfx/pdfx_plugin.h>
|
||||||
#include <printing/printing_plugin.h>
|
#include <printing/printing_plugin.h>
|
||||||
|
#include <screen_retriever/screen_retriever_plugin.h>
|
||||||
|
#include <window_manager/window_manager_plugin.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
PdfxPluginRegisterWithRegistrar(
|
PdfxPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("PdfxPlugin"));
|
registry->GetRegistrarForPlugin("PdfxPlugin"));
|
||||||
PrintingPluginRegisterWithRegistrar(
|
PrintingPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("PrintingPlugin"));
|
registry->GetRegistrarForPlugin("PrintingPlugin"));
|
||||||
|
ScreenRetrieverPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
|
||||||
|
WindowManagerPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
pdfx
|
pdfx
|
||||||
printing
|
printing
|
||||||
|
screen_retriever
|
||||||
|
window_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user