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(
|
||||
|
||||
Reference in New Issue
Block a user