Add cross-platform printing API (com.codename1.printing)#5217
Add cross-platform printing API (com.codename1.printing)#5217shai-almog wants to merge 2 commits into
Conversation
Printer/PrintResult/PrintResultListener with Display plumbing and implementations in all ports: JavaSE (PrinterJob/Desktop.print), Android (android.print + PrintHelper), iOS (UIPrintInteractionController), JavaScript (blob URL + hidden iframe), Windows (PrintDlg + GDI with Windows.Data.Pdf page rendering). Includes PrinterSample. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
✅ ByteCodeTranslator Quality ReportTest & Coverage
Benchmark Results
Static Analysis
Generated automatically by the PR CI workflow. |
|
Compared 11 screenshots: 11 matched. |
|
Compared 128 screenshots: 128 matched. Native Android coverage
✅ Native Android screenshot tests passed. Native Android coverage
Benchmark ResultsDetailed Performance Metrics
|
|
Compared 125 screenshots: 125 matched. Benchmark ResultsDetailed Performance Metrics
|
|
Compared 125 screenshots: 125 matched. Benchmark ResultsDetailed Performance Metrics
|
Cloudflare Preview
|
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Compared 128 screenshots: 128 matched. Benchmark Results
Detailed Performance Metrics
|
|
Compared 128 screenshots: 128 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
|
Compared 124 screenshots: 124 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
|
Compared 121 screenshots: 121 matched. |

Summary
New cross-platform printing API that hands a document (PDF or image file in
FileSystemStorage) to the platform printing system, typically through the native print dialog.Core —
com.codename1.printing:Printerstatic facade (print(filePath, mimeType, listener),printPDF,printImagewhich encodes to a temp PNG), immutablePrintResult(COMPLETED / CANCELLED / FAILED factories, mirroringShareResult),PrintResultListener(invoked exactly once, on the EDT). Plumbed throughDisplay.print(...)(EDT-wrapping, same pattern asshare) with overridable defaults inCodenameOneImplementation.COMPLETED means "handed to the printing system"; platforms that can't observe the native dialog's outcome report it best-effort, documented per method.
Port implementations
PrinterJob+ native dialog (real cancel detection, aspect-fit); PDFs viaDesktop.printwith ajavax.printPDF-flavor fallbackandroid.print.PrintManager: PDFs through a streamingPrintDocumentAdapter, images through support-v4PrintHelper; job outcome viaPrintJobstate polling; all API-19+ types isolated in a@TargetApi(19)inner classUIPrintInteractionControllervia theIOSNativebridge, following thesocialShareWithCallbackcallback-id pattern; iPad presents from a rectopenFileAsBlob/BlobUtil) + hidden iframe +contentWindow.print(),afterprint+ fallback completioncn1_windows_print.cpp:PrintDlgWon the pump thread (sameSendMessagehandover as the file dialog,WM_APP+23), images via the shared WIC decoder + GDIStretchDIBits, PDFs via raw-ABIWindows.Data.Pdfpage rendering at printer DPI — no STL, no new link librariesAlso adds
Samples/samples/PrinterSample(prints a generated image and a downloaded PDF).Verification
mvn compileclean for core, javase, android, ios and windows modules; JS port compiles via the samejavacstep its build script uses; sample compiles against core.CleanTargetIntegrationTest#crossCompilesWindowsExeWithXwinpasses on this branch — full translate + clang-cl compile + lld-link of a Form app including the print code into a Windows PE (x64), against the current master port (noWM_APPmessage collision with the new file picker).cn1_windows_print.cppis also registered in the per-file clang-cl compile check.PrinterSample(native macOS print dialog, image print + cancel reporting).Not yet runtime-tested
iOS (ObjC mirrors the share pattern; needs a device build), Android dialog flow, Windows dialog→spool/PDF rendering on real hardware, and browser printing.
PrinterSampleis the quickest smoke test on each.🤖 Generated with Claude Code