forked from yaso_meth/mih-project
add printing to pdf document
This commit is contained in:
@@ -8,6 +8,9 @@ import 'package:patient_manager/mih_objects/arguments.dart';
|
||||
import 'package:syncfusion_flutter_core/theme.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import "package:universal_html/html.dart" as html;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
class FullScreenFileViewer extends StatefulWidget {
|
||||
final FileViewArguments arguments;
|
||||
@@ -43,6 +46,25 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
||||
});
|
||||
}
|
||||
|
||||
void printDocument() async {
|
||||
print("Printing ${widget.arguments.path.split("/").last}");
|
||||
http.Response response = await http.get(Uri.parse(widget.arguments.link));
|
||||
var pdfData = response.bodyBytes;
|
||||
try {
|
||||
await Printing.layoutPdf(
|
||||
onLayout: (PdfPageFormat format) async => pdfData);
|
||||
} on Exception catch (_) {
|
||||
print("Print Error");
|
||||
}
|
||||
}
|
||||
|
||||
void shareDocument() async {
|
||||
http.Response response = await http.get(Uri.parse(widget.arguments.link));
|
||||
var pdfData = response.bodyBytes;
|
||||
await Printing.sharePdf(
|
||||
bytes: pdfData, filename: widget.arguments.path.split("/").last);
|
||||
}
|
||||
|
||||
MIHAction getActionButton() {
|
||||
return MIHAction(
|
||||
icon: const Icon(
|
||||
@@ -156,6 +178,19 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: isPDF,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
printDocument();
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.print,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
html.window.open(
|
||||
@@ -169,6 +204,16 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
shareDocument();
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.share,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -245,264 +290,5 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
||||
secondaryActionDrawer: null,
|
||||
bottomNavBar: null,
|
||||
);
|
||||
// if (getExtType(widget.arguments.path).toLowerCase() == "pdf") {
|
||||
// return Scaffold(
|
||||
// body: SafeArea(
|
||||
// child: Stack(
|
||||
// children: [
|
||||
// Container(
|
||||
// width: width,
|
||||
// padding: const EdgeInsets.only(top: 20.0),
|
||||
// decoration: BoxDecoration(
|
||||
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
// ),
|
||||
// child: Column(
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// const SizedBox(height: 50),
|
||||
// SizedBox(
|
||||
// width: width - zoomOut,
|
||||
// height: height - 70,
|
||||
// child: SfPdfViewerTheme(
|
||||
// data: SfPdfViewerThemeData(
|
||||
// backgroundColor: MzanziInnovationHub.of(context)!
|
||||
// .theme
|
||||
// .primaryColor(),
|
||||
// ),
|
||||
// child: SfPdfViewer.network(
|
||||
// widget.arguments.link,
|
||||
// controller: pdfViewerController,
|
||||
// initialZoomLevel: startZoomLevel,
|
||||
// pageSpacing: 2,
|
||||
// maxZoomLevel: 5,
|
||||
// interactionMode: PdfInteractionMode.pan,
|
||||
// onDocumentLoaded: (details) {
|
||||
// setState(() {
|
||||
// currentPage = pdfViewerController.pageNumber;
|
||||
// currentPageCount = pdfViewerController.pageCount;
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// Positioned(
|
||||
// top: 5,
|
||||
// left: 2,
|
||||
// width: 50,
|
||||
// height: 50,
|
||||
// child: IconButton(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context);
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.fullscreen_exit,
|
||||
// color:
|
||||
// MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Positioned(
|
||||
// top: 5,
|
||||
// right: 2,
|
||||
// //width: 50,
|
||||
// height: 50,
|
||||
// child: Row(
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// mainAxisAlignment: MainAxisAlignment.end,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// pdfViewerController.previousPage();
|
||||
// //print(pdfViewerController.);
|
||||
// //if (pdfViewerController.pageNumber > 1) {
|
||||
// setState(() {
|
||||
// currentPage = pdfViewerController.pageNumber;
|
||||
// });
|
||||
// // }
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.arrow_back,
|
||||
// color: MzanziInnovationHub.of(context)!
|
||||
// .theme
|
||||
// .secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// // SizedBox(
|
||||
// // width: 40,
|
||||
// // height: 40,
|
||||
// // child: MIHTextField(
|
||||
// // controller: cuntrController,
|
||||
// // hintText: "",
|
||||
// // editable: true,
|
||||
// // required: false),
|
||||
// // ),
|
||||
// Text(
|
||||
// "$currentPage / $currentPageCount",
|
||||
// style: const TextStyle(fontSize: 20),
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// pdfViewerController.nextPage();
|
||||
// //print(pdfViewerController.pageNumber);
|
||||
// //if (pdfViewerController.pageNumber < currentPageCount) {
|
||||
// setState(() {
|
||||
// currentPage = pdfViewerController.pageNumber;
|
||||
// });
|
||||
// //}
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.arrow_forward,
|
||||
// color: MzanziInnovationHub.of(context)!
|
||||
// .theme
|
||||
// .secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// if (zoomOut > 0) {
|
||||
// setState(() {
|
||||
// zoomOut = zoomOut - 100;
|
||||
// });
|
||||
// } else {
|
||||
// setState(() {
|
||||
// pdfViewerController.zoomLevel =
|
||||
// startZoomLevel + 0.25;
|
||||
// startZoomLevel = pdfViewerController.zoomLevel;
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.zoom_in,
|
||||
// color: MzanziInnovationHub.of(context)!
|
||||
// .theme
|
||||
// .secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// if (pdfViewerController.zoomLevel > 1) {
|
||||
// setState(() {
|
||||
// pdfViewerController.zoomLevel =
|
||||
// startZoomLevel - 0.25;
|
||||
// startZoomLevel = pdfViewerController.zoomLevel;
|
||||
// });
|
||||
// } else {
|
||||
// if (zoomOut < (width - 100)) {
|
||||
// setState(() {
|
||||
// zoomOut = zoomOut + 100;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.zoom_out,
|
||||
// color: MzanziInnovationHub.of(context)!
|
||||
// .theme
|
||||
// .secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// html.window.open(
|
||||
// widget.arguments.link,
|
||||
// // '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||
// 'download');
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.download,
|
||||
// color: MzanziInnovationHub.of(context)!
|
||||
// .theme
|
||||
// .secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// } else {
|
||||
// return Scaffold(
|
||||
// body: Stack(
|
||||
// children: [
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(top: 50.0),
|
||||
// width: width,
|
||||
// // height: height,
|
||||
// decoration: BoxDecoration(
|
||||
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
// //borderRadius: BorderRadius.circular(25.0),
|
||||
// // border: Border.all(
|
||||
// // color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
// // width: 5.0),
|
||||
// ),
|
||||
// child: Column(
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// children: [
|
||||
// const SizedBox(height: 20),
|
||||
// Expanded(
|
||||
// child: InteractiveViewer(
|
||||
// maxScale: 5.0,
|
||||
// //minScale: 0.,
|
||||
// child: Image.network(widget.arguments.link),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// Positioned(
|
||||
// top: 5,
|
||||
// left: 2,
|
||||
// width: 50,
|
||||
// height: 50,
|
||||
// child: IconButton(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context);
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.fullscreen_exit,
|
||||
// color:
|
||||
// MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Positioned(
|
||||
// top: 5,
|
||||
// right: 2,
|
||||
// width: 50,
|
||||
// height: 50,
|
||||
// child: IconButton(
|
||||
// onPressed: () {
|
||||
// html.window.open(
|
||||
// widget.arguments.link,
|
||||
// // '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||
// 'download');
|
||||
// },
|
||||
// icon: Icon(
|
||||
// Icons.download,
|
||||
// color:
|
||||
// MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// size: 35,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,29 +339,26 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
windowBody: [
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MIHFileField(
|
||||
controller: selectedFileController,
|
||||
hintText: "Select File",
|
||||
editable: false,
|
||||
required: true,
|
||||
onPressed: () async {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['jpg', 'png', 'pdf'],
|
||||
);
|
||||
if (result == null) return;
|
||||
final selectedFile = result.files.first;
|
||||
setState(() {
|
||||
selected = selectedFile;
|
||||
});
|
||||
MIHFileField(
|
||||
controller: selectedFileController,
|
||||
hintText: "Select File",
|
||||
editable: false,
|
||||
required: true,
|
||||
onPressed: () async {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['jpg', 'png', 'pdf'],
|
||||
);
|
||||
if (result == null) return;
|
||||
final selectedFile = result.files.first;
|
||||
setState(() {
|
||||
selected = selectedFile;
|
||||
});
|
||||
|
||||
setState(() {
|
||||
selectedFileController.text = selectedFile.name;
|
||||
});
|
||||
},
|
||||
),
|
||||
setState(() {
|
||||
selectedFileController.text = selectedFile.name;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
SizedBox(
|
||||
|
||||
@@ -7,12 +7,16 @@
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <gtk/gtk_plugin.h>
|
||||
#include <printing/printing_plugin.h>
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) gtk_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
|
||||
gtk_plugin_register_with_registrar(gtk_registrar);
|
||||
g_autoptr(FlPluginRegistrar) printing_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin");
|
||||
printing_plugin_register_with_registrar(printing_registrar);
|
||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
gtk
|
||||
printing
|
||||
url_launcher_linux
|
||||
)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import device_info_plus
|
||||
import google_sign_in_ios
|
||||
import no_screenshot
|
||||
import path_provider_foundation
|
||||
import printing
|
||||
import shared_preferences_foundation
|
||||
import sign_in_with_apple
|
||||
import syncfusion_pdfviewer_macos
|
||||
@@ -21,6 +22,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin"))
|
||||
NoScreenshotPlugin.register(with: registry.registrar(forPlugin: "NoScreenshotPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
SignInWithApplePlugin.register(with: registry.registrar(forPlugin: "SignInWithApplePlugin"))
|
||||
SyncfusionFlutterPdfViewerPlugin.register(with: registry.registrar(forPlugin: "SyncfusionFlutterPdfViewerPlugin"))
|
||||
|
||||
@@ -81,6 +81,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.11.0"
|
||||
barcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: barcode
|
||||
sha256: ab180ce22c6555d77d45f0178a523669db67f95856e3378259ef2ffeb43e6003
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.8"
|
||||
bazel_worker:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -89,6 +97,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
bidi:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: bidi
|
||||
sha256: "9a712c7ddf708f7c41b1923aa83648a3ed44cfd75b04f72d598c45e5be287f9d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.12"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -712,6 +728,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.0"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
path_provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -760,6 +784,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
pdf:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: pdf
|
||||
sha256: "05df53f8791587402493ac97b9869d3824eccbc77d97855f4545cf72df3cae07"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.11.1"
|
||||
pdf_widget_wrapper:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pdf_widget_wrapper
|
||||
sha256: c930860d987213a3d58c7ec3b7ecf8085c3897f773e8dc23da9cae60a5d6d0f5
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -800,6 +840,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
printing:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: printing
|
||||
sha256: b576764370c920b510cedf3eac7dc199d6d4af34336d608e97546392c0113362
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.13.3"
|
||||
protobuf:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -824,6 +872,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
qr:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: qr
|
||||
sha256: "5a1d2586170e172b8a8c8470bbbffd5eb0cd38a66c0d77155ea138d3af3a4445"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
realtime_client:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -54,6 +54,8 @@ dependencies:
|
||||
#google_maps_flutter_web: ^0.5.10
|
||||
url_strategy: ^0.3.0
|
||||
no_screenshot: ^0.3.1
|
||||
printing: ^5.13.3
|
||||
pdf: ^3.11.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <app_links/app_links_plugin_c_api.h>
|
||||
#include <printing/printing_plugin.h>
|
||||
#include <syncfusion_pdfviewer_windows/syncfusion_pdfviewer_windows_plugin.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
AppLinksPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
|
||||
PrintingPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("PrintingPlugin"));
|
||||
SyncfusionPdfviewerWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("SyncfusionPdfviewerWindowsPlugin"));
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
app_links
|
||||
printing
|
||||
syncfusion_pdfviewer_windows
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user