Skip to content
Open
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
14 changes: 11 additions & 3 deletions pdf/lib/src/widgets/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,14 @@ class Outline extends Anchor {
}

void _buildOutline(Context context) {
if (_outline != null) {
return;
final outline = _outline;
// a footer may have pushed this outline to the next page. if that happens, we have to replace it with a new outline with the correct page number
var shouldRemove = false;
if (outline != null) {
if (outline.page == context.pageLabel) {
return;
}
shouldRemove=true;
}

_outline = PdfOutline(
Expand Down Expand Up @@ -693,7 +699,9 @@ class Outline extends Anchor {
candidate = candidate.parent!;
actualLevel--;
}

if (shouldRemove) {
candidate.outlines.remove(outline);
}
candidate.add(_outline!);
}
}
4 changes: 3 additions & 1 deletion pdf/lib/src/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ class TableOfContent extends StatelessWidget {
thickness: 0.2,
)),
SizedBox(width: 8),
DelayedWidget(build: (_) => Text('${c.page}')),
DelayedWidget(build: (_) =>
Text('${c.page}')
),
],
),
),
Expand Down
30 changes: 30 additions & 0 deletions pdf/test/widget_toc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import 'dart:io';
import 'dart:math';

import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -79,6 +80,35 @@ void main() {
);
});

test('page number with footer', () {
pdf.addPage(
Page(
build: (final context) {
return Column(
children: [TableOfContent()],
);
},
),
);
pdf.addPage(
MultiPage(
footer: (final Context context) {
return Container(
margin: const EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
child: Text(
'Page ${context.pageNumber} of ${context.pagesCount}',
),
);
},
build: (final context) => [
Header(text: 'a', level: 1),
Text(LoremText().paragraph(600)),
Header(text: 'b', level: 1),
],
),
);
});

tearDownAll(() async {
final file = File('widgets-toc.pdf');
await file.writeAsBytes(await pdf.save());
Expand Down