dart_pdf
dart_pdf copied to clipboard
iOS 15 - Thermal Receipt Printer page too long
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
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.
Any triage notes on this? Should I make a PR?
Yes, please create a PR and we can talk about it.
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
You need to fork, work on your own repo and do a pull request.
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
Closing this stale issue because it has no activity.