Skip to content

Printing problem #1877

@xerceslazo

Description

@xerceslazo

Describe the bug
On Flutter Print Preview, it doesn't show the image to be printed

To Reproduce
Code snippet to reproduce the behavior:

  final pdf = pw.Document();
  final Uint8List imageData = await rootBundle.load('assets/images/test.png').then((value) => value.buffer.asUint8List());

  final pageFormat = PdfPageFormat.letter.copyWith(
    marginLeft: 2 * PdfPageFormat.mm
  );

  pdf.addPage(
    pw.Page(
      pageFormat: pageFormat,
      build: (pw.Context context) {
        return pw.Stack(
          children: [
            pw.Positioned(
              left: 28 * PdfPageFormat.mm,
              top: 10 * PdfPageFormat.mm,
              child: pw.Image(pw.MemoryImage(Uint8List.fromList(imageData)),
                  width: 4 * PdfPageFormat.mm),
            ),
            pw.Positioned(
              left: 35 * PdfPageFormat.mm,
              top: 10 * PdfPageFormat.mm,
              child: pw.Image(pw.MemoryImage(Uint8List.fromList(imageData)),
                  width: 4 * PdfPageFormat.mm),
            ),
            pw.Positioned(
              left: 41 * PdfPageFormat.mm,
              top: 10 * PdfPageFormat.mm,
              child: pw.Image(pw.MemoryImage(Uint8List.fromList(imageData)),
                  width: 4 * PdfPageFormat.mm),
            )
          ],
        );
      },
    ),
  );
  // Print preview
  final result = await Printing.layoutPdf(
    onLayout: (PdfPageFormat format) async => pdf.save(),

  );

Expected behavior
Print preview should show the image you should be printing

Screenshots

Flutter Doctor

printingtest2 flutter doctor -v
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.0 24A335 darwin-arm64, locale en-US) [732ms]
    • Flutter version 3.29.3 on channel stable at /Users/syddeo/Desktop/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (5 months ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3

[!] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [805ms]
    • Android SDK at /Users/syddeo/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0) [4.5s]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [9ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2025.1) [9ms]
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)

[✓] VS Code (version 1.104.0) [8ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.118.0

[✓] VS Code (version 1.103.0) [8ms]
    • VS Code at /Users/syddeo/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.118.0

[✓] Connected device (4 available) [6.1s]
    • iPhone 16 Pro (mobile)          • BC669AE6-5EDE-4FF7-A5A0-70A71194BAC5 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-0
      (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.0 24A335 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.0 24A335 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 128.0.6613.138
    ! Error: Browsing on the local area network for Isaac Newton. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [538ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Desktop (please complete the following information):

  • [*] iOS - I using iOS
  • Android
  • Browser
  • Windows
  • Linux

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions