Skip to content

Commit

Permalink
Allow parsing of streams with extra whitespaces (#51)
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
NicolaVerbeeck authored Jan 7, 2024
1 parent e321174 commit a2e6775
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.1

- Fix parsing PDFs where stream or startxref ends with extra whitespace (#50)

## 0.5.0

- Add support for web by using the archive package. (#48)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parser/pdf_object_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class PDFObjectParser {
}

Future<PDFStreamObject?> _parseStream(PDFDictionary dictionary) async {
final line = await ReaderHelper.readLine(_buffer);
if ('tartxref' == line) return null;
final line = (await ReaderHelper.readLine(_buffer))?.trim();
if (line == 'tartxref') return null;
assert('tream' == line);

var object = dictionary[PDFNames.length];
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_pdf_reader
description: Small pure-dart library for parsing PDF files. Supports reading all pdf structures
version: 0.5.0
version: 0.5.1
repository: https://github.com/NicolaVerbeeck/dart_pdf_reader
issue_tracker: https://github.com/NicolaVerbeeck/dart_pdf_reader/issues
topics: [pdf, parser]
Expand All @@ -17,6 +17,6 @@ dependencies:
dev_dependencies:
lints: ">=2.0.0 <4.0.0"
test: ^1.21.0
dcli: ^3.0.2
dcli: ^3.2.4
mocktail: ^1.0.0
convert: ^3.1.1
26 changes: 26 additions & 0 deletions test/parser/pdf_stream_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,31 @@ void streamParserTests() {
final raw = await stream.readRaw();
expect(raw, [97, 98, 99]);
});
test('Test stream extra space, with data', () async {
final stream =
await createParserFromString('<</Length 3>>stream \nabcendstream')
.parse();
expect(stream, isA<PDFStreamObject>());

stream as PDFStreamObject;
expect(stream.dictionary.entries, {
const PDFName('Length'): const PDFNumber(3),
});
expect(stream.length, 3);
expect(stream.offset, 21);
final raw = await stream.readRaw();
expect(raw, [97, 98, 99]);
});
test('Test startxref keyword having trailing whitespace', () async {
final stream =
await createParserFromString('<</Length 3>>startxref \nabcendstream')
.parse();
expect(stream, isA<PDFDictionary>());

stream as PDFDictionary;
expect(stream.entries, {
const PDFName('Length'): const PDFNumber(3),
});
});
});
}

0 comments on commit a2e6775

Please sign in to comment.