0

我有一个生成小收据格式的 Web 应用程序。
当打印到通用/txt 打印机时.. 没有任何内容打印到工作表上

这是打印的样本.. 已 删除

请问有没有办法可以将此网页打印到通用/txt 打印机

这是html

        <style>
    body{
        font-family:"Courier New", Courier, monospace;  
        font-size:13px;
    }
    .f1{
        text-transform:uppercase;
        display:block;
        text-align:center;
    }

    .f2{
        text-transform:uppercase;
        display:block;
        margin-left:10px;
    }

    .border_bottom{
        border-bottom:2px dashed #000;
    }
    .border_top{
        border-top:2px dashed #000;
    }

    .body_table{
        border:1px dashed #CCCCCC;
        padding:.5em;
    }
    </style>
    </head>

    <body onload="window.print();">
    <table width="300" cellpadding="0" cellspacing="0" class="body_table">
        <tr>
            <td><span class="f1">Official Receipt</span></td>
        </tr>
        <tr>
            <td><span class="f1">DreamWorks Pharmaceutical Industries Limited GH.</span></td>
        </tr>
        <tr>
            <td><span class="f1">Plot 14 Blk 8A</span></td>
        </tr> 
    <tr>
            <td class="border_bottom"><span class="f1">0241093621</span></td>
        </tr>   


    <tr>
            <td class=""><span class="f2">RECEIPT NO.: 0241093621</span></td>
        </tr>     

    <tr>
            <td class=""><span class="f2">VAT REG #.: </span></td>
        </tr>

    <tr>
            <td class=""><span class="f2">cashier.: </span></td>
        </tr> 

    <tr>
            <td class=""><span class="f2">date.:  time: </span></td>
        </tr>

    <tr>
            <td class="border_bottom"><span class="f2">customer.:  time: </span></td>
        </tr>

    <tr>
        <td>
            <table width="98%" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="5%"><span class="f2">QTY</span></td>
                    <td width="60%"><span class="f2">item</span></td>
                    <td width="15"><span class="f2">price</span></td>
                    <td width="15"><span class="f2">amt.</span></td>                
                </tr> 


                        <tr>
                        <td class="f2">52</td>
                        <td>MALAREX TABS</td>
                        <td>2.6</td>
                        <td>135.20</td>
                        </tr>
                                </table>
        </td>
    </tr> 
    <tr>
        <td class="border_top border_bottom">
        <table width="100%" cellpadding="0" cellspacing="0" align="left" id="print_table7"> 
                    <tr>
                        <Td class="ash_backg" width="53%"><span>Subtotal</span></Td>
                        <td width="47%" align="right">135.20</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Discount</span></Td>
                        <td align="right">0.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>VAT</span></Td>
                        <td align="right">0.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Total Due</span></Td>
                        <td align="right">135.20</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Paid</span></Td>
                        <td align="right">135.20</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Change</span></Td>
                        <td align="right">0.00</td>
                    </tr>                                                
                 </table>
        </td>
    </tr>  

    <tr>
        <td>Thank You dear customer</td>
    </tr>

    <tr>
        <td>VAT Inclusive Where Applicable</td>
    </tr>                           
    </table>
    </body>

这是收据格式 HTML

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/plain; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    @media screen{
        body{
            font-family:"Courier New", Courier, monospace;  
            font-size:13px;
        }
        .f1{
            text-transform:uppercase;
            display:block;
            text-align:center;
        }

        .f2{
            text-transform:uppercase;
            display:block;
            margin-left:10px;
        }

        .border_bottom{
            border-bottom:2px dashed #000;
        }
        .border_top{
            border-top:2px dashed #000;
        }

        .body_table{
            border:1px dashed #CCCCCC;
            padding:.5em;
        }   
    }

    @media print{
        body{
            font-family:"Courier New", Courier, monospace;  
            font-size:8px;
            width:250px;
        }
    }
    </style>
    </head>

    <body onload="window.print();">
    <table width="300" cellpadding="0" cellspacing="0" class="body_table">
        <tr>
            <td><span class="f1">Official Receipt</span></td>
        </tr>
        <tr>
            <td><span class="f1">DreamWorks Pharmaceutical Industries Limited GH.</span></td>
        </tr>
        <tr>
            <td><span class="f1">Plot 14 Blk 8A</span></td>
        </tr> 
    <tr>
            <td class="border_bottom"><span class="f1">0241093621</span></td>
        </tr>   


    <tr>
            <td class=""><span class="f2">RECEIPT NO.: 0241093621</span></td>
        </tr>     

    <tr>
            <td class=""><span class="f2">VAT REG #.: </span></td>
        </tr>

    <tr>
            <td class=""><span class="f2">cashier.: </span></td>
        </tr> 

    <tr>
            <td class=""><span class="f2">date.:  time: </span></td>
        </tr>

    <tr>
            <td class="border_bottom"><span class="f2">customer.:  time: </span></td>
        </tr>

    <tr>
        <td>
            <table width="98%" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="5%"><span class="f2">QTY</span></td>
                    <td width="60%"><span class="f2">item</span></td>
                    <td width="15"><span class="f2">price</span></td>
                    <td width="15"><span class="f2">amt.</span></td>                
                </tr> 


                        <tr>
                        <td class="f2">6</td>
                        <td>MALAREX TABS</td>
                        <td>0</td>
                        <td>0</td>
                        </tr>

                        <tr>
                        <td class="f2">1</td>
                        <td>PARAFEN PLUS TAB.</td>
                        <td>0</td>
                        <td>0</td>
                        </tr>

                        <tr>
                        <td class="f2">5</td>
                        <td>ASTHAX INHALER</td>
                        <td>5</td>
                        <td>25</td>
                        </tr>
                                </table>
        </td>
    </tr> 
    <tr>
        <td class="border_top border_bottom">
        <table width="100%" cellpadding="0" cellspacing="0" align="left" id="print_table7"> 
                    <tr>
                        <Td class="ash_backg" width="53%"><span>Subtotal</span></Td>
                        <td width="47%" align="right">25.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Discount</span></Td>
                        <td align="right">0.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>VAT</span></Td>
                        <td align="right">0.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Total Due</span></Td>
                        <td align="right">25.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Paid</span></Td>
                        <td align="right">25.00</td>
                    </tr>
                    <tr>
                        <Td class="ash_backg"><span>Change</span></Td>
                        <td align="right">0.00</td>
                    </tr>                                                
                 </table>
        </td>
    </tr>  

    <tr>
        <td>Thank You dear customer</td>
    </tr>

    <tr>
        <td>VAT Inclusive Where Applicable</td>
    </tr>                           
    </table>
    </body>
    </html>
4

2 回答 2

1

Yes, you can print the document as the above and you have to use the separate style sheet for the screen display and printing. CSS rules are:

@media screen
  {
  //Css
  }

@media print{
    @page { size:250px 375px; margin: 4px }
    body{font-family:"Courier New", Courier, monospace;  font-size:8px;}
    .f1{text-transform:uppercase; display:block; text-align:center;}
    .f2{text-transform:uppercase; display:block; margin-left:10px;}
    .border_bottom{ border-bottom:2px dashed #000;}
    .border_top{border-top:2px dashed #000;}
    .body_table{border:1px dashed #CCCCCC; padding:.5em;}
}

In these you can describe the page size, colors and many more things Just Google the CSS Print specification and you would know more.

But, I think the another problem involved in your i.e. print using POS printer to print it. For that I would Like to suggest the way are:

Two simple ways to do it, depending on how much interference you're willing to accept in your interface.

Firstly, you can just use JavaScript to trigger your receipt page/iframe to print. This option is a little klunky, as it requires the cashier to confirm the print in the system dialogue.

But secondly, you always have the option of sharing each station's printer on the network. Your server-side component can print directly to it. And if it's a *nix server, it's pretty easy to do once each station's printer has added to / shared with the server. In PHP (with CUPs installed, I imagine):

// attempt to pipe to 'lp -d printername'
if (`echo "{$text}" | lp -d {$printer_name}`) {
    // print successful
    return true;
} else {
    // print failed
    return false;
}

For second method, If you're running a windows server, it's probably much more complicated.

于 2013-03-05T12:15:19.383 回答
1

您可以使用 CSS 媒体类型。使用一个用于屏幕,使其看起来不错,另一个用于打印,使其清晰。

例如:

@media screen
  {
  p.test {font-family:verdana,sans-serif;font-size:14px;}
  }
@media print
  {
  p.test {font-family:times,serif;font-size:10px;}
  }
于 2013-03-05T12:10:29.167 回答