Skip to content

feat: add Invoice PDF export with print and HTML download#95

Open
adarsh-yadav1 wants to merge 1 commit into
seetadev:mainfrom
adarsh-yadav1:feat/invoice-pdf-export
Open

feat: add Invoice PDF export with print and HTML download#95
adarsh-yadav1 wants to merge 1 commit into
seetadev:mainfrom
adarsh-yadav1:feat/invoice-pdf-export

Conversation

@adarsh-yadav1
Copy link
Copy Markdown

Summary

Closes #94

Adds a self-contained Invoice PDF export feature to GovtInvoice. Users can export the current spreadsheet invoice as a styled, print-ready PDF or download it as a standalone HTML file — both with zero extra dependencies.

What Changed

New files

File Purpose
Govt-Billing-React/src/hooks/useInvoicePDF.ts Core hook — exportAsPDF() and downloadHTML()
Govt-Billing-React/src/components/InvoicePDF/InvoicePDFModal.tsx IonModal UI for choosing export format

How It Works

FAB menu → "Export as PDF"
  └── InvoicePDFModal opens
        ├── "Export as PDF"    → printViaIframe()
        │     └── Hidden iframe injected into page
        │           └── iframe.contentWindow.print() fires
        │                 └── User selects "Save as PDF"
        └── "Download as HTML" → Blob + <a download> → .html file

Key implementation decisions

  • Hidden iframe instead of window.open — avoids popup blockers entirely, works on localhost and Capacitor WebView
  • No DOM mutation for canvas handling — canvas elements are replaced with [Chart — view in app] via regex on the HTML string, avoiding React re-render conflicts (insertBefore NotFoundError)
  • Zero new dependencies — uses only browser-native APIs (Blob, URL.createObjectURL, iframe.contentWindow.print())

UI Flow

  1. Tap the FAB button (☰) at bottom right
  2. Action sheet opens → tap "Export as PDF"
  3. InvoicePDFModal opens showing:
    • Current invoice filename
    • Two export options with descriptions
    • Tip about "Save as PDF" in print dialog
  4. Choose an option → toast confirms action → modal closes

Screenshots

image image image

Testing Checklist

  • Export as PDF — print dialog opens via hidden iframe
  • Download as HTML — .html file downloads with correct filename
  • Modal opens and closes correctly
  • Toast confirmation shows after each action
  • Works on Chrome (desktop)
  • Works on Firefox (desktop)
  • Android Capacitor
  • iOS Capacitor

No New Dependencies

Uses only browser-native APIs — no jsPDF, html2canvas, or any other package added. package.json is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add PDF export option for invoices

1 participant