with capturing the width of the printing screen with jQuery

Asked

Viewed 453 times

0

I have the following code:

HTML

<table style="width: 100%">
    <tr>
        <th>
            teste
        </th>
    </tr>
</table>

JQUERY

    // Imprime a página
    window.print();
    // Redireciona página
    window.location = 'link';

Good the problem I have and the following. When I printed on an A4 sheet the table occupies the whole screen correctly. But I put together a receipt and I want to print it on a non-tax printer, and it uses tape that ends 80mm, and the table is cut, as if it only prints half.

Good the solution I have in mount, and make jQuery capture the width of the print sheet and change the table css.

Can anyone do it? Or have some better solution?

  • 3

    Have you tried measuring in millimeters? Although using "web" technology for this will always be impromptu, but perhaps using absolute measures breaks a branch. What is important to understand in the current difficulty is: whenever using hammer with screw, the result will be desired.

  • I tried to put everything inside a div with width: 350px; but it’s coming out all tiny. There must be some way to generate a web recycle to be printed on a non tax printer

  • 2

    Use mm and not px. Put the fonts in mm and the width in mm (and even then, it doesn’t always work).

1 answer

1

Still can’t know print screen information on JS, so even you can’t capture the print screen width on jQuery.

Something you can do is use @media queries of CSS3 and make page changes according to the width/height of the print screen.

That might be enough.

(In min-width you must specify the sheet widths.)

/* semelhante à 90mm */
@media print and (min-width: 80mm) {
    table {
        width: 350px;
    }
}

/* ... */
@media print and (min-width: 121mm) {
    table {
        width: 450px;
    }
}

/* +A5, A4, ... */
@media print and (min-width: 152mm) {
    table {
        width: 100%;
    }
}

You can declare how many @media print want.

  • I tried here but it didn’t work, Look if I’m doing it right: @media print and (min-width: '80mm') {&#xA; .w100 {&#xA; width: 350px;&#xA; }&#xA;}

  • 1

    @Hugoborges Remove the quotation marks

  • 2

    Maybe this will help the question of mm because I don’t think it’s right to use this measure px for Web: https://www.w3.org/Style/Examples/007/units.pt_BR.html

  • @nicematt could give me an example of how I put 350px for when the leaf leaf is less than or equal to 90mm and if it is A4 leaf stay 100%

  • 4

    @iLeonardoCarvgarlic I would recommend you to read your own links for feedback. According to its own link, mm is not good for CANVAS, and the user wants the measure on paper. Absolute measure is precisely the problem he described in the question: "They are not recommended for use on canvas because screen sizes vary greatly. A large screen can be 60cm (24in); a small and portable, maybe only 8cm." Yet: "No, the drives have nothing to do with the properties, but have everything to do with the output media: screen or paper. "

  • 1

    Well I wanted just one more conversion even not using the mm and yes the px because semantically each unit inserted within a page can hinder maintenance and standardize is the best alternative and using the comments to remember the value inserted.

  • 1

    In fact, just to complement, taken from the recommended link: http://i.stack.Imgur.com/Cpyed.png

  • 1

    good for what I could notice the line @media print and (min-width: 152mm) { and able to recognize the width of the ok screen. there is no way I put the width value of the screen in PX in the width property?

  • @Hugoborges No, CSS does not offer to do this, or at least currently.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.