diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/primitives/pdf_string.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/primitives/pdf_string.dart index ee428257..54821bc8 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/primitives/pdf_string.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/primitives/pdf_string.dart @@ -21,9 +21,12 @@ class PdfString implements IPdfPrimitive { if (data![0] == 0xfe && data![1] == 0xff) { this.value = decodeBigEndian(data, 2, data!.length - 2); isHex = false; - data = []; - for (int i = 0; i < this.value!.length; i++) { - data!.add(this.value!.codeUnitAt(i).toUnsigned(8)); + // 16-byte fields (e.g. /ID) are raw binary identifiers — never + // append decoded character bytes to them. + if (data!.length != 16) { + for (int i = 0; i < this.value!.length; i++) { + data!.add(this.value!.codeUnitAt(i).toUnsigned(8)); + } } } else { this.value = byteToString(data!); diff --git a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart index f4ba520c..b2c64879 100644 --- a/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart +++ b/packages/syncfusion_flutter_pdfviewer/lib/src/pdfviewer.dart @@ -2313,8 +2313,17 @@ class SfPdfViewerState extends State with WidgetsBindingObserver { _performTextExtraction(); } } + + Uint8List? signatureBytes; + if (_document != null) { + try { + signatureBytes = _renderDigitalSignatures(); + } catch (_) { + // Digital-signature flattening is best-effort; fall back to raw bytes. + } + } final int pageCount = await _plugin.initializePdfRenderer( - _renderDigitalSignatures() ?? _pdfBytes, + signatureBytes ?? _pdfBytes, _password, ); _pdfViewerController._pageCount = pageCount; @@ -2352,12 +2361,17 @@ class SfPdfViewerState extends State with WidgetsBindingObserver { } catch (e) { if (widget.onDocumentLoadFailed != null) { if (widget.password == '' || widget.password == null) { - widget.onDocumentLoadFailed!( - PdfDocumentLoadFailedDetails( - 'Empty Password Error', - 'The provided `password` property is empty so unable to load the encrypted document.', - ), - ); + // Only report "no password" when the dialog won't be shown. + // When canShowPasswordDialog is true the UI handles it, + // so firing onDocumentLoadFailed here is confusing noise. + if (!widget.canShowPasswordDialog) { + widget.onDocumentLoadFailed!( + PdfDocumentLoadFailedDetails( + 'Empty Password Error', + 'The provided `password` property is empty so unable to load the encrypted document.', + ), + ); + } } else { widget.onDocumentLoadFailed!( PdfDocumentLoadFailedDetails( @@ -2409,7 +2423,10 @@ class SfPdfViewerState extends State with WidgetsBindingObserver { /// Render and flatten digital signatures in the PDF document. Uint8List? _renderDigitalSignatures() { if (_document!.form.fields.count != 0) { - final PdfDocument pdfDocument = PdfDocument(inputBytes: _pdfBytes); + final PdfDocument pdfDocument = PdfDocument( + inputBytes: _pdfBytes, + password: _password, + ); bool isDigitalSignature = false; Uint8List? digitalSignatureBytes;