Skip to content

Commit

Permalink
Fix a bug that caused a crash when retrieving the text of the last pa…
Browse files Browse the repository at this point in the history
…ge of the entire document on iOS
  • Loading branch information
AlessioLuciani committed Mar 30, 2020
1 parent 7da63b7 commit eb8e7d8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.1

* An issue that caused a crash on iOS, when retrieving the text of the last page of the entire document, has been fixed.


## 0.1.0

* The plugin is ready to be used.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
pdf_text: ^0.1.0
pdf_text: ^0.1.1
```
## Usage
Expand Down Expand Up @@ -55,6 +55,11 @@ Read the text of a page of the document:
String pageText = await page.text;
```

## Functioning

This plugin applies lazy loading for the text contents of the pages. The text is cached page per page. When you request the text of a page for the first time, it is parsed and stored in memory, so that the second access will be faster. Anyway, the text of pages that are not requested is not loaded. This mechanism
allows you not to waste time loading text that you will probably not use. When you request the text content of the entire document, only the pages that have not been loaded yet, are then loaded.

## Public Methods

### PDFDoc
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.0"
version: "0.1.1"
petitparser:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/SwiftPdfTextPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class SwiftPdfTextPlugin: NSObject, FlutterPlugin {
if doc == nil {
return
}
let text = doc!.page(at: pageNumber)!.string
let text = doc!.page(at: pageNumber-1)!.string
DispatchQueue.main.sync {
result(text)
}
Expand All @@ -87,7 +87,7 @@ public class SwiftPdfTextPlugin: NSObject, FlutterPlugin {
}
var missingPagesTexts = [String]()
for pageNumber in missingPagesNumbers {
missingPagesTexts.append(doc!.page(at: pageNumber)!.string!)
missingPagesTexts.append(doc!.page(at: pageNumber-1)!.string!)
}
DispatchQueue.main.sync {
result(missingPagesTexts)
Expand Down
2 changes: 1 addition & 1 deletion lib/pdf_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class PDFPage {
if (_text == null) {
try {
_text = await _channel.invokeMethod('getDocPageText', {"path": _parentDoc._file.path,
"number": _number});
"number": number});
} on Exception catch (e) {
return Future.error(e);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pdf_text
description: A Flutter plugin used to extract text from PDF documents.
version: 0.1.0
version: 0.1.1
homepage: https://github.com/AlessioLuciani/flutter-pdf-text

environment:
Expand Down

0 comments on commit eb8e7d8

Please sign in to comment.