Giter VIP home page Giter VIP logo

Comments (3)

TranceDevCode avatar TranceDevCode commented on June 9, 2024

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

from electron-pos-printer.

TranceDevCode avatar TranceDevCode commented on June 9, 2024

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>
`

from electron-pos-printer.

maheshsamudra avatar maheshsamudra commented on June 9, 2024

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.

from electron-pos-printer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.