Lovable Prompt
Add native printing functionality to my app using the Despia SDK from: https://www.npmjs.com/package/despia-nativeFirst, install the package: Important: Served files via HTTPS must have proper content-type headers for optimal printing functionality.Please follow the installation instructions for the “despia-native” npm package closely, and do not modify my instructions. Implementation as mentioned is critical.
npm install despia-nativeThen import it: import despia from 'despia-native'Create a printing system that uses print URLs like: despia("printitem://?jobName={PRINT-NAME}&printItem={CDN-FILE-URL}") to open the native print dialog and allow users to print documents and images through their device’s built-in printing system.This feature requires native capabilities which will be fully provided by the “despia-native” npm package, no additional native libraries are needed!
Installation
Install the Despia package from NPM:Usage
1. Import the SDK
2. Execute Print Job
Call thedespia() function with a Print URL containing the required parameters:
URL Parameters
- jobName (required): The name of the print job that will appear in the print dialog and printer queue
- printItem (required): The HTTPS URL of the image or PDF file to print
Example Use Cases
Printing a PDF document:File Server Requirements
Files served via HTTPS must have proper headers:- Content-Type: Appropriate MIME type for the file:
- PDF:
application/pdf - JPEG:
image/jpeg - PNG:
image/png - GIF:
image/gif - WebP:
image/webp
- PDF:
- CORS Headers: Ensure proper CORS configuration if files are hosted on a different domain
- HTTPS Required: All print items must be served over HTTPS for security
Resources
- NPM Package
- View full NPM documentation for additional configuration options