Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when generating PDF/A - Concurrent modification during iteration: Instance of '_HashSet<PdfObject<PdfDataType>>'. #1822

Open
2 of 5 tasks
pldelattre opened this issue Feb 24, 2025 · 3 comments
Labels
bug Something isn't working needs triage

Comments

@pldelattre
Copy link

pldelattre commented Feb 24, 2025

Describe the bug
Crash when generating PDF/A using pdf 3.11.3

To Reproduce
Code snippet to reproduce the behavior:

Future<Uint8List> loadColorProfile() async {
  try {
    ByteData data = await rootBundle.load('assets/pdfColorProfiles/sRGB2014.icc');
    return data.buffer.asUint8List();
  } catch (e) {
    debugPrint('Error loading asset: $e');
    return Uint8List(0); 
  }
}

  Future<Uint8List> generatePdf(
      [PdfPageFormat format = PdfPageFormat.a4]) async {

    final pdf = pw.Document(
      version: PdfVersion.pdf_1_5,
      compress: true,
      metadata: PdfaRdf(
        invoiceRdf: PdfaFacturxRdf().create(),
      ).create(),
    );

    PdfaColorProfile(pdf.document, await loadColorProfile());
    
    PdfaAttachedFiles(
      pdf.document,
      {
        'factur-x.xml': '<test></test>',
      },
    );

     return pdf.save();
 )

     await generatePdf();   // EXCEPTION

     debugPrint('Never reached... Exception on previous line');

Exception doesn't occur if I remove:

    PdfaAttachedFiles(
      pdf.document,
      {
        'factur-x.xml': '<test></test>',
      },
    );

ERROR

Image

Expected behavior
Should not crash

Screenshots

Image

Flutter Doctor

[✓] Flutter (Channel stable, 3.24.3, on macOS 14.7.3 23H417 darwin-arm64, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.0)
[✓] Connected device (4 available)
[✓] Network resources

Desktop (please complete the following information):

  • iOS
  • Android
  • Browser
  • Windows
  • Linux

Smartphone (please complete the following information):

  • OS: Mac OS 14.7.3
  • Browser: Chrome 133.0.6943.99
@pldelattre pldelattre added bug Something isn't working needs triage labels Feb 24, 2025
@pldelattre
Copy link
Author

@ilaurillard

@ilaurillard
Copy link
Contributor

see #1820

@pldelattre
Copy link
Author

Thanks @ilaurillard. I confirm the pull request fixes the bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants