dart_pdf
dart_pdf copied to clipboard
`TableOfContent` shows incorrect page number when footer margin pushes `Header` to the next page in `MultiPage`
Describe the bug
To Reproduce Code snippet to reproduce the behavior:
import 'dart:io';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
void main() async {
final file = File('asdf.pdf');
final pdf = await (pw.Document(pageMode: PdfPageMode.outlines)
..addPage(
pw.Page(
build: (final context) {
return pw.Column(
children: [pw.TableOfContent()],
);
},
),
)
..addPage(
pw.MultiPage(
footer: (final pw.Context context) {
return pw.Container(
margin: const pw.EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
child: pw.Text(
'Page ${context.pageNumber} of ${context.pagesCount}',
),
);
},
build: (final context) => [
pw.Header(text: 'a', level: 1),
pw.Text(pw.LoremText().paragraph(600)),
pw.Header(text: 'b', level: 1),
],
),
))
.save();
await file.writeAsBytes(pdf);
}
Expected behavior
table of contents says "a" is on page 2 and "b" is on page 3
Screenshots

Flutter Doctor
[√] Flutter (Channel stable, 3.0.4, on Microsoft Windows [Version 10.0.19044.1826], locale en-AU)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.8.3)
[!] Android Studio (not installed)
[√] IntelliJ IDEA Community Edition (version 2019.2)
[√] IntelliJ IDEA Ultimate Edition (version 2022.1)
[√] IntelliJ IDEA Ultimate Edition (version 2022.2)
[√] VS Code, 64-bit edition (version 1.65.2)
[√] Connected device (4 available)
[√] HTTP Host Availability
Desktop (please complete the following information):
- [X] iOS
- [X] Android
- [ ] Browser
- [X] Windows
- [ ] Linux
Smartphone (please complete the following information):
- Device: iPhone 13
- OS: 15.1.1
- Browser safari
- Version idk