Plan sharing: "Print / Save as PDF" on the mobile app

The printable one-page plan layout (lib/plan-share.js planPrintHTML) was
web-only: printPlan() renders it into a hidden iframe and calls
window.print(), which Android's WebView does not implement.

On mobile the same HTML is handed to the OS print flow via a small
first-party `Print` Capacitor plugin (one method, printHtml), which is
where the user picks "Save as PDF" / "Save to Files" or a real printer.
Web is unchanged.

- Android (PrintPlugin.java): load the HTML into an off-screen WebView and,
  once loaded, drive it through the system PrintManager. A strong ref keeps
  the WebView alive until the job spools. Registered in MainActivity next
  to InstallPlugin.
- iOS (PrintPlugin.swift + .m): UIPrintInteractionController with a
  UIMarkupTextPrintFormatter. Files added to App.xcodeproj.
- lib/mobile.js: printHtml() wrapper (registerPlugin('Print')).
- sheets.jsx: the MOBILE branch of "Print / Save as PDF" calls printHtml;
  the web branch still calls printPlan.

No new dependency — the OS renders the PDF. Native code is not exercised by
the pipeline; run the manual APK job and check on device.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DBkhHLqWtSYrPdsNE11PiP
This commit is contained in:
HenryandClaude Sonnet 5 committed 2026-09-08 11:19:25 +01:00
1 parent acff80348f
commit 8e18e77437
7 files changed
+155 -7

No files matched your search

+12
View File
@@ -172,6 +172,18 @@ export async function shareExport(json, filename) {
await Share.share({ title: filename, url: w.uri })
}
// Hand a self-contained HTML document (lib/plan-share.js planPrintHTML) to the OS print flow.
// Android routes it through the system PrintManager — "Save as PDF", "Save to Drive", a real
// printer; iOS through the print sheet — "Save to Files" (as PDF), share, print. Either way the
// platform renders the PDF, so no PDF library rides in the bundle. The local `Print` plugin is
// registered natively (android MainActivity, ios PrintPlugin.m); on the web build this file's
// callers gate on MOBILE and never reach here.
export async function printHtml(html, name) {
const { registerPlugin } = await import('@capacitor/core')
const Print = registerPlugin('Print')
await Print.printHtml({ html, name })
}
// "Auto-backup on changes" (Settings): a dated snapshot dropped into the Documents folder —
// visible in Files (iOS) / a file manager (Android), unlike the private mirror nativeSave keeps
// — so whatever the user points at that folder (a sync app, a manual copy) always has something