Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint
continue-on-error: true

- name: Build
run: npm run build

verify-ios:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Verify iOS
run: npm run verify:ios

verify-android:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Verify Android
run: npm run verify:android

verify-web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Verify Web
run: npm run verify:web
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ captures

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Package.resolved
/.build
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [7.1.0] - 2025-11-15

### Added
- Swift Package Manager (SPM) support for iOS
- Package.swift file for SPM integration

### Changed
- iOS projects can now be integrated using Swift Package Manager as an alternative to CocoaPods

## [7.0.1] - Previous Release

### Changed
- Updated for Capacitor 7 support
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "WebnativellcCapacitorPrintWebview",
platforms: [.iOS(.v14)],
products: [
.library(
name: "WebnativellcCapacitorPrintWebview",
targets: ["PrintWebviewPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
],
targets: [
.target(
name: "PrintWebviewPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/PrintWebviewPlugin"),
.testTarget(
name: "PrintWebviewPluginTests",
dependencies: ["PrintWebviewPlugin"],
path: "ios/Tests/PrintWebviewPluginTests")
]
)
58 changes: 54 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Capacitor Print WebView

Capacitor Plugin for a Print Preview of the WebView. Supports Capacitor 7.
A Capacitor plugin that enables printing the current WebView content on iOS and Android devices. This plugin provides a native print dialog that allows users to print or save as PDF the content displayed in your Capacitor application's WebView.

## Features

- 🖨️ Print WebView content directly from your Capacitor app
- 📱 Native print dialog on iOS and Android
- 💾 Save as PDF option (platform dependent)
- 🎨 Preserves styling and formatting from your web content
- ⚡ Simple, promise-based API
- 🔧 Supports Capacitor 7

## Platforms

- ✅ iOS
- ✅ Android
- ❌ Web (not applicable)

## Install

Expand All @@ -9,16 +24,51 @@ npm install @webnativellc/capacitor-print-webview
npx cap sync
```

### Swift Package Manager (SPM)

This plugin also supports installation via Swift Package Manager for iOS projects. Add the following to your `Package.swift`:

```swift
dependencies: [
.package(url: "https://github.com/damiant/capacitor-print-webview.git", from: "7.1.0")
]
```

## Usage

Calling `print()` will print the webview.
The plugin provides a simple `print()` method that displays the native print dialog with the current WebView content:

```typescript
import { PrintWebview } from '@webnativellc/capacitor-print-webview';
...
await PrintWebview.print();

// Print the current WebView content
async function printCurrentPage() {
try {
await PrintWebview.print();
console.log('Print dialog opened successfully');
} catch (error) {
console.error('Error opening print dialog:', error);
}
}
```

### Example Use Cases

- **Receipts & Invoices**: Allow users to print transaction receipts
- **Reports**: Enable printing of generated reports and documents
- **Tickets**: Print event tickets or booking confirmations
- **Content Sharing**: Provide a print option for articles or documentation

### What Gets Printed?

The plugin prints the entire content of the WebView, including:
- All visible HTML content
- CSS styling and formatting
- Images and graphics
- Dynamic content generated by JavaScript

**Note**: The content is rendered as it appears in the WebView at the time `print()` is called.

## API

<docgen-index>
Expand Down
2 changes: 1 addition & 1 deletion WebnativellcCapacitorPrintWebview.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.homepage = package['repository']['url']
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '14.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
Expand Down
9 changes: 9 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.DS_Store
.build
Loading