docs.rs failed to build adao99-tauri-plugin-printer-1.0.10
Please check the
build logs for more information.
See
Builds for ideas on how to fix a failed build,
or
Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault,
open an issue.
Tauri Plugin Printer
Interface with printers through Powershell
Buy Me Coffee
PayPal
BuyMeCoffee
Install
If you are installing from npm and crate.io package registry, make sure the mayor and minor versions for both packages are the same, otherwise, the API may not match.
Crate: https://crates.io/crates/tauri-plugin-printer
Install latest version:
cargo add tauri-plugin-printer
Or add the following to your Cargo.toml
for spesific version:
src-tauri/Cargo.toml
[dependencies]
tauri-plugin-printer = { version = "1.0.10" }
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
pnpm add tauri-plugin-printer
npm add tauri-plugin-printer
yarn add tauri-plugin-printer
Usage
First you need to register the core plugin with Tauri:
src-tauri/src/main.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_printer::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
import {printers, print, print_file, jobs, job, restart_job, pause_job, resume_job, remove_job} from "tauri-plugin-printer";
const list = await printers()
const list = await printers(id)
const data = [
{
type: 'image',
url: 'https://randomuser.me/api/portraits/men/43.jpg', position: 'center', width: '160px', height: '60px', },{
type: 'text', value: 'SAMPLE HEADING',
style: {fontWeight: "700", textAlign: 'center', fontSize: "24px"}
},{
type: 'text', value: 'Secondary text',
style: {textDecoration: "underline", fontSize: "10px", textAlign: "center", color: "red"}
},{
type: 'barCode',
value: '023456789010',
height: 40, width: 2, displayValue: true, fontsize: 12,
},{
type: 'qrCode',
value: 'https://github.com/Hubertformin/electron-pos-printer',
height: 55,
width: 55,
style: { margin: '10 20px 20 20px' }
},{
type: 'table',
style: {border: '1px solid #ddd'},
tableHeader: ['Animal', 'Age'],
tableBody: [
['Cat', 2],
['Dog', 4],
['Horse', 12],
['Pig', 4],
],
tableFooter: ['Animal', 'Age'],
tableHeaderStyle: { backgroundColor: '#000', color: 'white'},
tableBodyStyle: {'border': '0.5px solid #ddd'},
tableFooterStyle: {backgroundColor: '#000', color: 'white'},
},{
type: 'table',
style: {border: '1px solid #ddd'}, tableHeader: [{type: 'text', value: 'People'}, {type: 'image', path: path.join(__dirname, 'icons/animal.png')}],
tableBody: [
[{type: 'text', value: 'Marcus'}, {type: 'image', url: 'https://randomuser.me/api/portraits/men/43.jpg'}],
[{type: 'text', value: 'Boris'}, {type: 'image', url: 'https://randomuser.me/api/portraits/men/41.jpg'}],
[{type: 'text', value: 'Andrew'}, {type: 'image', url: 'https://randomuser.me/api/portraits/men/23.jpg'}],
[{type: 'text', value: 'Tyresse'}, {type: 'image', url: 'https://randomuser.me/api/portraits/men/53.jpg'}],
],
tableFooter: [{type: 'text', value: 'People'}, 'Image'],
tableHeaderStyle: { backgroundColor: 'red', color: 'white'},
tableBodyStyle: {'border': '0.5px solid #ddd'},
tableFooterStyle: {backgroundColor: '#000', color: 'white'},
},
]
await print(data, {
id: "idprinter" preview: true, page_size: {
width: 300, heigth: 400 };
print_setting: {
orientation: "landscape",
method: "simplex", paper: "A4", scale: "noscale", repeat: 1, range: { from: 1,
to: 3
}
}
})
await print_file({
id: "idfromlistprinter",
path: 'F:/path/to/file.pdf',
file: BufferData,
print_setting: {
orientation: "landscape",
method: "simplex", paper: "A4", scale: "noscale", repeat: 1, range: { from: 1,
to: 3
}
}
})
await jobs()
await jobs(idprinter)
await job(id)
await restart_job()
await restart_job(id)
await pause_job()
await pause_job(id)
await resume_job()
await resume_job(id)
await remove_job()
await remove_job(id)
License
Code: (c) 2023 - Present Alfian Lensun.
MIT where applicable.