pdf blur issue fix

This commit is contained in:
Surendiran 2026-08-08 12:08:24 +05:30
parent 863c08b918
commit d5c16857e3

View File

@ -47,8 +47,10 @@ const _capturePadding = 16.0;
const _maxMeasureHeight = 1400.0; const _maxMeasureHeight = 1400.0;
const _enrollmentMaxMeasureHeight = 1020.0; const _enrollmentMaxMeasureHeight = 1020.0;
const _minCaptureHeight = 360.0; const _minCaptureHeight = 360.0;
const _captureTimeout = Duration(seconds: 20); const _captureTimeout = Duration(seconds: 30);
const _pdfEmbedMaxWidth = 960; /// Target embed width (~200 DPI on A4 landscape content area) for sharp text.
const _pdfEmbedMaxWidth = 1800;
const _pdfJpegQuality = 92;
const _logoAsset = 'assets/Nhance-Logo-Final 1.png'; const _logoAsset = 'assets/Nhance-Logo-Final 1.png';
const _pdfLogoHeight = 28.0; const _pdfLogoHeight = 28.0;
const _pdfPageMargin = pw.EdgeInsets.fromLTRB(10, 14, 10, 14); const _pdfPageMargin = pw.EdgeInsets.fromLTRB(10, 14, 10, 14);
@ -101,7 +103,8 @@ Future<void> _preloadFonts() async {
} }
} }
/// Shrinks and JPEG-encodes tab screenshots so [doc.save] stays fast. /// Optionally downscales and JPEG-encodes tab screenshots for PDF embed.
/// Keeps high resolution so dashboard text/charts stay sharp when zoomed.
Uint8List _compressTabImageForPdf(Uint8List pngBytes) { Uint8List _compressTabImageForPdf(Uint8List pngBytes) {
try { try {
final decoded = img.decodePng(pngBytes); final decoded = img.decodePng(pngBytes);
@ -112,11 +115,13 @@ Uint8List _compressTabImageForPdf(Uint8List pngBytes) {
processed = img.copyResize( processed = img.copyResize(
decoded, decoded,
width: _pdfEmbedMaxWidth, width: _pdfEmbedMaxWidth,
interpolation: img.Interpolation.average, interpolation: img.Interpolation.cubic,
); );
} }
return Uint8List.fromList(img.encodeJpg(processed, quality: 82)); return Uint8List.fromList(
img.encodeJpg(processed, quality: _pdfJpegQuality),
);
} catch (e) { } catch (e) {
debugPrint('PDF export: image compress skipped ($e)'); debugPrint('PDF export: image compress skipped ($e)');
return pngBytes; return pngBytes;
@ -293,10 +298,12 @@ Future<void> _waitForPaint() async {
} }
double _capturePixelRatio({required bool isEnrollmentTab}) { double _capturePixelRatio({required bool isEnrollmentTab}) {
// 2x+ capture is required for crisp text when screenshots are
// scaled into A4 landscape PDF pages (especially on Flutter web).
if (kIsWeb) { if (kIsWeb) {
return isEnrollmentTab ? 0.85 : 1.0; return isEnrollmentTab ? 1.75 : 2.0;
} }
return isEnrollmentTab ? 1.1 : 1.35; return isEnrollmentTab ? 1.75 : 2.25;
} }
Future<ui.Image?> _rasterizeBoundary( Future<ui.Image?> _rasterizeBoundary(