Comments (5)
What I've been doing is similar to @mariapaulinar. Set a maximum number of characters for a line and do the formatting yourself. Determine the length of the left string, and the right string and calculate the number of spaces you must insert between them.
It works. But having a table feature would definitely be easier. If I can find some time, I'll look into adding more advanced layout methods.
from escposencoder.
The next version of EscPosEncoder will support tables with a syntax similar to this:
let result = encoder
.table(
[
{ width: 36, marginRight: 2, align: 'left' },
{ width: 10, align: 'right' }
],
[
[ 'Item 1', '€ 10,00' ],
[ 'Item 2', '15,00' ],
[ 'Item 3', '9,95' ],
[ 'Item 4', '4,75' ],
[ 'Item 5', '211,05' ],
[ '', '='.repeat(10) ],
[ 'Total', (encoder) => encoder.bold().text('€ 250,75').bold() ],
]
)
.encode()
from escposencoder.
Maybe this code can help you (It was made with Angular):
const encoder = new EscPosEncoder();
let result = encoder
.codepage('cp852')
.newline()
.newline()
.align('center')
.line('Recibo de caja')
.bold(true)
.line('FACTURA SALDO PAGO')
.bold(false);
const maxChar = 11;
for (const item of resp.facturas) {
const cantFactura = (item.numeroFactura.toString().length <= maxChar) ? maxChar - item.numeroFactura.toString().length : 0;
const cantSaldo = (formatNumber(item.saldo, 'en-US').length <= maxChar) ? maxChar - formatNumber(item.saldo, 'en-US').length : 0;
const cantPago = (formatNumber(item.valorConsignar, 'en-US').length <= maxChar) ? maxChar - formatNumber(item.valorConsignar, 'en-US').length : 0;
const line = item.numeroFactura + ' '.repeat(cantFactura) + ' $' + formatNumber(item.saldo, 'en-US') + ' '.repeat(cantSaldo) + ' $' + formatNumber(item.valorConsignar, 'en-US') + ' '.repeat(cantPago);
result = result.line(line);
}
result = result
.line('-------------------------------')
.line('TOTAL PAGADO ' + resp.totalPagado)
.newline()
.newline()
.line('Formas Pago')
.line('-------------------------------');
for (const item of resp.formasPago) {
result = result.line(item.tipo + ' $' + item.valor);
}
result = result
.line('-------------------------------')
.line('TOTAL PAGADO ' + resp.totalPagado)
.newline()
.newline()
.newline()
.encode();
from escposencoder.
Hi, @mariapaulinar your code example was very helpful. Thank you
Yes, it will be easier. Thank you for this package very helpful. @NielsLeenheer
from escposencoder.
Hi @NielsLeenheer.
I used this .table( ... ) syntax and it is not working.
Do you have a demo
This my code using Ionic Angular but an error says .table( ) is not a function.
I think I did a wrong way. Please help me with a working example
const encoder = new EscPosEncoder();
const result = encoder.initialize();
result
.align('center')
.newline()
.line('Transaction Receipt')
.bold(false)
.align('left')
.line('Transaction Number: ' + this.generatedNumber)
.line('Transaction Date: ' + this.dateTime)
.newline()
.newline()
.line('-------------------------------')
.table(
[
{ width: 36, marginRight: 2, align: 'left' },
{ width: 10, align: 'right' }
],
[
[ 'Item 1', '50' ],
[ 'Item 2', '60' ],
[ 'Item 3', '10' ],
[ 'Item 4', '40' ],
[ 'Item 5', '60' ],
[ 'Total', '220' ],
]
)
.newline()
.newline()
.newline()
.encode();
from escposencoder.
Related Issues (20)
- CP874 Mapping Error
- Compatible with JSPrintManager?
- How to add codepage GB18030?
- QRCode not working as expected HOT 2
- New npm package HOT 7
- Cannot install on M1 Mac (ARM64) HOT 2
- Add display text parameter when printing barcode
- Publish a new version with auto encode and with the table functionality HOT 2
- Print image issue ( incomplete printing / encode error ) HOT 6
- Pure Browser JS Example HOT 3
- Failed to execute 'getImageData' HOT 1
- How To Insert Data Array in to Encoder? HOT 1
- cutting HOT 3
- How to print a horizontal line and font size increase
- Hello, how can I print Chinese HOT 1
- esc-pos-encoder error with NODE_MODULE_VERSION HOT 1
- I'm sorry but
- Add multiline support for "newLine" command
- Table with border and table auto layout
- Image printed with empty spaces in between HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from escposencoder.