Skip to content

Commit a622fa8

Browse files
Add getter for the list of the authors of a document
1 parent 1bf2d0e commit a622fa8

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.0
2+
3+
* A class for the PDF document information has been added. Now this information
4+
is retrieved on the initialization of the document.
5+
16
## 0.2.2
27

38
* Code formatting has been improved and minor issues solved.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add this to your package's `pubspec.yaml` file:
1818

1919
```yaml
2020
dependencies:
21-
pdf_text: ^0.2.2
21+
pdf_text: ^0.3.0
2222
```
2323
2424
## Usage

example/lib/main.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ class _MyAppState extends State<MyApp> {
9393
Future _pickPDFText() async {
9494
File file = await FilePicker.getFile();
9595
_pdfDoc = await PDFDoc.fromFile(file);
96-
print(_pdfDoc.info.producer);
97-
print(_pdfDoc.info.creator);
98-
print(_pdfDoc.info.creationDate);
99-
print(_pdfDoc.info.modificationDate);
100-
print(_pdfDoc.info.subject);
101-
print(_pdfDoc.info.keywords);
102-
print(_pdfDoc.info.title);
103-
print(_pdfDoc.info.author);
10496
setState(() {});
10597
}
10698

lib/pdf_text.dart

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,38 @@ class PDFDocInfo {
204204
this._title,
205205
this._subject);
206206

207-
/// Gets the author of the document. Returns null if no author exists.
207+
/// Gets the author of the document. This contains the original string of the
208+
/// authors contained in the document. Therefore there might be multiple
209+
/// authors separated by comma. Returns null if no author exists.
208210
String get author => _author;
209211

212+
/// Gets the list of authors of the document. This is inferred by splitting
213+
/// the author string by comma. Returns null if no author exists.
214+
List<String> get authors {
215+
if (author == null) {
216+
return null;
217+
}
218+
var authorString = author.replaceAll(";", ",");
219+
authorString = authorString.replaceAll("&", ",");
220+
authorString = authorString.replaceAll("and", ",");
221+
List<String> splitted = authorString.split(",");
222+
List<String> ret = List();
223+
for (var token in splitted) {
224+
var start = 0;
225+
var end = token.length - 1;
226+
while (start < token.length && token[start] == ' ') {
227+
start++;
228+
}
229+
while (end >= 0 && token[end] == ' ') {
230+
end--;
231+
}
232+
if (end - start >= 0) {
233+
ret.add(token.substring(start, end + 1));
234+
}
235+
}
236+
return ret;
237+
}
238+
210239
/// Gets the creation date of the document. Returns null if no creation
211240
/// date exists.
212241
DateTime get creationDate => _creationDate;

0 commit comments

Comments
 (0)