dart_pdf
dart_pdf copied to clipboard
`TooManyPagesException` when change the `fit` parameter in `Image` "widget"
I have a code which inserts an image with resulution 1875x1058. (But actually the resolution does not affect the output)
Image(
MemoryImage(_image),
fit: BoxFit.contain,
alignment: Alignment.topCenter,
width: pageFormat.availableWidth,
height: pageFormat.availableHeight,
),
It prints too small for the page with margins 1cm from any side. So I tried to make the image fit the the availableWidth
, i.e.
Image(
MemoryImage(_image),
fit: BoxFit.fitWidth,
alignment: Alignment.topCenter,
width: pageFormat.availableWidth,
height: pageFormat.availableHeight,
),
But I got the error. Moreover any value which is different from BoxFix.contains generate the same exception TooManyPagesException
. Why is it? What does it mean? And how make image really fit the available space?
══╡ EXCEPTION CAUGHT BY PRINTING ╞══════════════════════════════════════════════════════════════════
The following TooManyPagesException was thrown while generating a PDF:
Instance of 'TooManyPagesException'
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3 throw_
packages/pdf/src/widgets/multi_page.dart 251:9 generate
packages/pdf/src/widgets/document.dart 117:9 addPage
packages/cemacs/framework/services/pdf_builder.dart 104:7 build
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
dart-sdk/lib/async/zone.dart 1661:54 runUnary
dart-sdk/lib/async/future_impl.dart 162:18 handleValue
dart-sdk/lib/async/future_impl.dart 846:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 875:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 647:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 721:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7 <fn>
PageFormat: "PdfPageFormat 612x792 margins:72, 72, 72, 72"
════════════════════════════════════════════════════════════════════════════════════════════════════
const double inch = 72.0;
const double cm = inch / 2.54;
Image(
MemoryImage(_image),
alignment: Alignment.topCenter,
width: 15.0 * cm,
height: 20.0 * cm,
),
```
Also you may try to put into a container and give height and width to it.
@bksbora thank you for your answer but the question was why fit
parameter is not working and cause an exception. Moreover I don't understand how your code helps? My code is the same and I need image tp occupy the whole page and not only 15x20 cm. That is why I specified availableWidth
and availableHeight
.
Please let us know when you solve :) Hope you best !