Skip to content

add pdf creation with/without OCR #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Libraries.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Open Source libraries used in the Scanbot SDK Flutter Plugin version 4.2.2:
Open Source libraries used in the Scanbot SDK Flutter Plugin version 4.2.3:

//-------------------------------------------------------------
collection 1.17.1
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/classical_components/cropping_custom_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {

CroppingController? croppingController;

_CroppingScreenWidgetState(this.currentPage) {}
_CroppingScreenWidgetState(this.currentPage);

@override
void initState() {
Expand Down
76 changes: 36 additions & 40 deletions lib/ui/preview_document_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ class _DocumentPreviewState extends State<DocumentPreview> {
title: const Text('Save as PDF'),
onTap: () {
Navigator.pop(context);
_createPdf();
_createPDF();
},
),
ListTile(
leading: const Icon(Icons.picture_as_pdf),
title: const Text('Save as PDF with OCR'),
onTap: () {
Navigator.pop(context);
_createOcrPdf();
_createPdfWithOCR();
},
),
ListTile(
Expand Down Expand Up @@ -330,34 +330,9 @@ class _DocumentPreviewState extends State<DocumentPreview> {
}
}

Future<void> _createPdf() async {
if (!await _checkHasPages(context)) {
return;
}
if (!await checkLicenseStatus(context)) {
return;
}

final dialog = ProgressDialog(context,
type: ProgressDialogType.Normal, isDismissible: false);
dialog.style(message: 'Creating PDF ...');
try {
dialog.show();
var options = const PdfRenderingOptions(pageSize: PageSize.A4);
final pdfFileUri =
await ScanbotSdk.createPdf(_pageRepository.pages, options);
await dialog.hide();
await showAlertDialog(context, pdfFileUri.toString(),
title: 'PDF file URI');
} catch (e) {
print(e);
await dialog.hide();
}
}

Future<void> _importImage() async {
try {
final image = await ImagePicker().getImage(source: ImageSource.gallery);
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
await _createPage(Uri.file(image?.path ?? ''));
} catch (e) {
print(e);
Expand Down Expand Up @@ -429,7 +404,7 @@ class _DocumentPreviewState extends State<DocumentPreview> {
dialog.show();
try {
final result = await ScanbotSdk.performOcr(_pages,
OcrOptions(languages: ['en', 'de'], shouldGeneratePdf: false));
OcrOptions(languages: ['en', 'de']));
await dialog.hide();
await showAlertDialog(
context, 'Plain text:\n' + (result.plainText ?? ''));
Expand All @@ -439,7 +414,32 @@ class _DocumentPreviewState extends State<DocumentPreview> {
}
}

Future<void> _createOcrPdf() async {
Future<void> _createPdfWithOCR() async {
if (!await _checkHasPages(context)) {
return;
}
if (!await checkLicenseStatus(context)) {
return;
}

final dialog = ProgressDialog(context,
type: ProgressDialogType.Normal, isDismissible: false);
dialog.style(message: 'Creating PDF with OCR ...');
try {
dialog.show();
var options = const PdfRenderingOptions(pageSize: PageSize.A4);
final pdfFileUri =
await ScanbotSdk.createPdf(_pageRepository.pages, options, shouldGeneratePdfWithOcr: true);
await dialog.hide();
await showAlertDialog(context, pdfFileUri.toString(),
title: 'PDF with OCR file URI');
} catch (e) {
print(e);
await dialog.hide();
}
}

Future<void> _createPDF() async {
if (!await _checkHasPages(context)) {
return;
}
Expand All @@ -449,18 +449,14 @@ class _DocumentPreviewState extends State<DocumentPreview> {

var dialog = ProgressDialog(context,
type: ProgressDialogType.Normal, isDismissible: false);
dialog.style(message: 'Performing OCR with PDF ...');
dialog.show();
dialog.style(message: 'Creating PDF ...');
try {
var result = await ScanbotSdk.performOcr(
_pages, OcrOptions(languages: ['en', 'de'], shouldGeneratePdf: true));
dialog.show();
var options = const PdfRenderingOptions(pageSize: PageSize.A4);
var result = await ScanbotSdk.createPdf(_pageRepository.pages, options, shouldGeneratePdfWithOcr: false);
await dialog.hide();
await showAlertDialog(
context,
'PDF File URI:\n' +
(result.pdfFileUri ?? '') +
'\n\nPlain text:\n' +
(result.plainText ?? ''));
await showAlertDialog(context, result.toString(),
title: 'PDF File URI');
} catch (e) {
print(e);
await dialog.hide();
Expand Down
7 changes: 3 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,9 @@ packages:
scanbot_sdk:
dependency: "direct main"
description:
name: scanbot_sdk
sha256: "473366a4e8e0275d4a5c1950f954e872c62099dd5c66e7ff9d3385b3fde46dda"
url: "https://pub.dev"
source: hosted
path: "../scanbot-sdk-flutter"
relative: true
source: path
version: "4.2.2"
shared_preferences:
dependency: "direct main"
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dependencies:
flutter:
sdk: flutter

scanbot_sdk: ^4.2.2
scanbot_sdk:
path: ../scanbot-sdk-flutter/

cupertino_icons: ^1.0.2

Expand Down