Open coycoylaniba opened 12 months ago
Hello. I have the same problem, but can't fix it... now i test with this package https://www.npmjs.com/package/escpos but return me another problem. One of the recommended solutions is to use Electron 12, I currently have version 13, I will be trying to downgrade to version 12 and try again... I am working on a project with:
VueJS, Express and Electron
node version 16.20 and npm version 8.19.4
I found a solution and this is working for me now, but using another package for VueJS and Electron, this is the package https://www.npmjs.com/package/electron-pos-printer-vue/v/1.0.9 if you are using something like Vuejs and Electron i share my code example here:
<button @click="imprimir">Imprimir</button>
<HelloWorld msg="Welcome to Your Vue.js App" />
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
const { PosPrinter } = require('electron').remote.require("electron-pos-printer-vue");
//const path = require("path");
export default {
name: 'App',
components: {
HelloWorld
},
methods: {
async imprimir() {
const options = {
preview: false, // Preview in window or print
width: '170px', // width of content body
margin: '0 0 0 0', // margin of content body
copies: 1, // Number of copies to print
printerName: 'ImpresoraBarata', // printerName: string, check with webContent.getPrinters()
//printerName: 'EPSON TM-T88V Receipt', // printerName: string, check with webContent.getPrinters()
timeOutPerLine: 400,
pageSize: { height: 301000, width: 71000 }, // page size
silent: true
}
const data = [
{
type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
value: 'SAMPLE HEADING',
//style: `text-align:center;`,
style: ''
}, {
type: 'text', // 'text' | 'barCode' | 'qrCode' | 'image' | 'table'
value: 'Secondary text',
//style: `text-align:left;color: red;`,
style: ''
}, {
type: 'barCode',
value: 'HB4587896',
height: 12, // height of barcode, applicable only to bar and QR codes
width: 1, // width of barcode, applicable only to bar and QR codes
displayValue: true, // Display value below barcode
fontsize: 8,
}, {
type: 'qrCode',
value: 'https://github.com/Hubertformin/electron-pos-printer',
height: 55,
width: 55,
style: ''
}, {
type: 'table',
// style the table
style: '',
// list of the columns to be rendered in the table header
tableHeader: ['Animal', 'Age'],
// multi dimensional array depicting the rows and columns of the table body
tableBody: [
['Cat', 2],
['Dog', 4],
['Horse', 12],
['Pig', 4],
],
// list of columns to be rendered in the table footer
tableFooter: ['Animal', 'Age'],
// custom style for the table header
tableHeaderStyle: 'background-color: #000; color: white;',
// custom style for the table body
tableBodyStyle: 'border: 0.5px solid #ddd',
// custom style for the table footer
tableFooterStyle: 'background-color: #000; color: white;',
}, {
type: 'table',
style: '', // style the table
// list of the columns to be rendered in the table header
//tableHeader: [{ type: 'text', value: 'Animal' }, { type: 'image', path: path.join(__dirname, 'assets/logo.png') }],
// multi dimensional array depicting the rows and columns of the table body
tableBody: [
[{ type: 'text', value: 'Cat' }],
[{ type: 'text', value: 'Dog' }],
[{ type: 'text', value: 'Horse' }],
[{ type: 'text', value: 'Pig' }],
],
// list of columns to be rendered in the table footer
tableFooter: [{ type: 'text', value: 'Animal' }],
// custom style for the table header
tableHeaderStyle: 'background-color: #000; color: white;',
// custom style for the table body
tableBodyStyle: 'border: 0.5px solid #ddd',
// custom style for the table footer
tableFooterStyle: 'background-color: #000; color: white;',
},
]
PosPrinter.print(data, options)
.then(() => { })
.catch((error) => {
console.error(error);
});
try {
await PosPrinter.print(data, options);
console.log("Impresión exitosa");
} catch (error) {
console.error("Error al imprimir:", error);
}
},
},
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
`
Ran into the same error. I inspected the node_modules/electron-pos-printer and it didn't have all the required files. Downgraded to 1.3.6 and it works just fine.
No typescript declaration.