dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

iOS 15 - Thermal Receipt Printer page too long

Open liammdowney opened this issue 2 years ago • 4 comments

Hello,

Describe the bug

I'm having an issue with printing on a continuous roll of 102mm receipt paper. So some reason, it attempts to print 2 meters of paper even though I'm specifying 340 mm in length (and 102mm width).

Code

 var printFormat = const PdfPageFormat(
        102 * PdfPageFormat.mm,
        340 * PdfPageFormat.mm,
      );

      var pdf = await Printing.convertHtml(
        format: printFormat,
        html: html,
      );

      await Printing.layoutPdf(
        format: printFormat,
        onLayout: (PdfPageFormat format) async => pdf,
      );

Expected behavior I expected the receipt to print preview and print the correct length. When you use sharePdf and then choose print from the share options, it all works as it should.

Screenshots

Screen Shot 2022-04-06 at 8 46 36 AM

Flutter Doctor

✓] Flutter (Channel stable, 2.8.1, on macOS 11.6 20G165 darwin-x64, locale en-CA)
    • Flutter version 2.8.1 at /Users/liam/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (4 months ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/liam/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/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

Desktop (please complete the following information):

  • [x] iOS
  • [ ] Android
  • [ ] Browser
  • [ ] Windows
  • [ ] Linux

Smartphone (please complete the following information):

  • Device: iPad (9th Generation)
  • OS: iOS 15.2
  • Browser: N/A
  • Version printing: ^5.7.2, pdf: ^3.7.1

Additional context

I think I've fixed the behaviour by overriding cutLengthFor in PrintJob.swift

Create a new variable.

 private var currentSize: CGSize?

Override UIPrintInteractionController with the cutLengthFor param.

public func printInteractionController(_ printInteractionController: UIPrintInteractionController, cutLengthFor paper: UIPrintPaper) -> CGFloat {
        if currentSize == nil{
            return  paper.paperSize.height
        }

        return currentSize!.height
       
    }

Assign the class level param currentSize to be the same as size

 func printPdf(name: String, withPageSize size: CGSize, andMargin margin: CGRect, withPrinter printerID: String?, dynamically dyn: Bool) {
        currentSize = size

This seems to fix the issue.

Screen Shot 2022-04-06 at 8 42 22 AM

liammdowney avatar Apr 06 '22 15:04 liammdowney

Any triage notes on this? Should I make a PR?

liammdowney avatar May 11 '22 17:05 liammdowney

Yes, please create a PR and we can talk about it.

DavBfr avatar May 11 '22 17:05 DavBfr

Will do. Do I need any special permissions to push a branch? Having permission issues with this repo but others seem to be working fine

liammdowney avatar May 12 '22 14:05 liammdowney

You need to fork, work on your own repo and do a pull request.

DavBfr avatar May 12 '22 15:05 DavBfr

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Apr 15 '23 00:04 github-actions[bot]

Closing this stale issue because it has no activity.

github-actions[bot] avatar Apr 21 '23 00:04 github-actions[bot]