electron-pos-printer icon indicating copy to clipboard operation
electron-pos-printer copied to clipboard

找不到 dist_electron/pos.html 文件

Open BoxCode7 opened this issue 2 years ago • 3 comments

我在主进程中进行调用,但是失败了,找不到pos.html文件

BoxCode7 avatar Jul 29 '22 08:07 BoxCode7

我在包里有看到pos.html文件,但在自动生成的打dist文件里面没有pos.html文件,是否与我用的是JavaScript而不是typeScript有关?

BoxCode7 avatar Jul 29 '22 08:07 BoxCode7

你好, 我为我迟到的回复道歉,我会尽快查看。 我正在努力使其与最新版本的电子兼容。 感谢您使用此软件包

Hubertformin avatar Sep 06 '22 10:09 Hubertformin

@Hubertformin could you please publish the latest code to npm....

janafsal avatar Sep 06 '22 10:09 janafsal

Hello @janafsal I just did!

Hubertformin avatar Oct 27 '22 12:10 Hubertformin

image

after update it don't prints, please see the above screenshot of preview window, could you please check?...thanking you in advance

janafsal avatar Oct 27 '22 14:10 janafsal

@janafsal Can you share the snippet of your code?

Hubertformin avatar Oct 27 '22 14:10 Hubertformin

 const { PosPrinter } = require("electron-pos-printer");
printerName="Microsoft Print to PDFline 361"
data = [
        {
          type: "text", // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
          value: "||---",
          style: `text-align:left;`,
          css: { "font-size": "12px",'margin':'0' },
        },
        {
          type: "text", // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
          value: "hello world",
          style: `text-align:center;`,
          css: { "font-weight": "700", "font-size": "18px","margin-top":"5px","text-decoration":"underline",'margin':'0'},
        }]
  const options = {
        preview: true, // Preview in window or print
        width: "250px", //  width of content body
        margin: "0 0 0 0", // margin of content body
        copies: 1, // Number of copies to print
        printerName: printerName, // printerName: string, check it at webContent.getPrinters()
        timeOutPerLine: 400,
        silent: true,
      };
const d = [...data];

     
        
        PosPrinter.print(d,options)
        .then(() => {
          // console.log('printed successfully')
          // const notification= new Notification({title:'Success',body:'Printed successfully'})
          // notification.show()
        })
        .catch((error) => {
          // console.error(error);
          const dialogOpts = {
            type: 'error',
            buttons: [],
            title: 'Print Error',
            message: error,
            detail:
              'error occured during the print job please contact administrator',
          }
        
          dialog.showMessageBox(dialogOpts).then((returnValue) => {
            
          })
        });

janafsal avatar Oct 27 '22 14:10 janafsal

Some major updates were done to styling, the css property is no longer supported. Please use style. style takes an object.

Using your example, look at the code below

const d = [
        {
            type: "text", // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
            value: "||---",
            style: {textAlign: 'left', fontSize: "12px", 'margin': '0'},
        },
        {
            type: "text", // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
            value: "hello world",
            style: {
                textAlign:`center`,
                fontWeight: "700",
                fontSize: "18px",
                marginTop: "5px",
                textDecoration: "underline",
                margin: '0'
            },
        }
    ]
image

Hubertformin avatar Oct 27 '22 14:10 Hubertformin

Some major updates were done to styling, the css property is no longer supported. Please use style. style takes an object.

Using your example, look at the code below

const d = [
        {
            type: "text", // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
            value: "||---",
            style: {textAlign: 'left', fontSize: "12px", 'margin': '0'},
        },
        {
            type: "text", // 'text' | 'barCode' | 'qrCode' | 'image' | 'table
            value: "hello world",
            style: {
                textAlign:`center`,
                fontWeight: "700",
                fontSize: "18px",
                marginTop: "5px",
                textDecoration: "underline",
                margin: '0'
            },
        }
    ]
image

thank you so much now its working.... so the style properties will be camel cased of css properties right?

janafsal avatar Oct 27 '22 15:10 janafsal

@janafsal Yes, exactly. Just like writing styles in jsx

Hubertformin avatar Oct 27 '22 15:10 Hubertformin

@janafsal Yes, exactly. Just like writing styles in jsx

Noted with thanks…

janafsal avatar Oct 27 '22 15:10 janafsal

May I ask if it is compatible with Electron

BoxCode7 avatar Oct 28 '22 05:10 BoxCode7

@BoxCode7, This is compatible with the latest version of electron.

Hubertformin avatar Oct 28 '22 06:10 Hubertformin

Although I have changed to other schemes, I still appreciate it very much. I will definitely use it again when I have the chance!

BoxCode7 avatar Oct 28 '22 06:10 BoxCode7