Style Your Receipt with CSS

I'm facing a problem with my BIXOLON printer where I'm trying to print a receipt using JavaScript, but the printing page size is too large.

Inner HTML:

<div id="divToPrint" class="invoice p-3 mb-3" style="max-height:100%">


<div class="row">
    <div class="col-12">
      <h4 style="text-align:center">
        <img src="<?php echo base_url()?>assets/dist/img/AdminLTELogo.png" class="img-responsive" style="max-width:100px;margin:0 auto;display:block"> 
        <br>
      </h4>
    </div>
  </div>
  <div class="row invoice-info">
    <div class="col-sm-4 invoice-col">
    </div>
    <div class="col-sm-4 invoice-col">
    </div>
    <div class="col-sm-4 invoice-col">
      <b>Invoice #<?php echo date('M Y').'-'.$id?></b><br>
      <br>
      <b>Payment:</b> <?php $amount?><br>
      <b>Duration:</b> <?php echo $duration ?>
    </div>
  </div>
  <div class="row">
    <div class="col-12 table-responsive">
      <table class="table table-striped">
        <thead>
          <tr>
            <th>Qty</th>
            <th>Station</th>
            <th>Serial</th>
            <th>Total</th>
          </tr>
        </thead>
        <tbody>        
          <tr>
            <td>1</td>
            <td><?php echo $stationTitle; ?> </td>
           <td><?php echo$ id?></td>
           <td><?php echo $amount?></td>
         </tr>
       </tbody>
     </table>
   </div>
 </div>
 <div class="row">
  <div class="col-6">
  </div>
  <div class="col-6">
    <p class="lead">Date <?php echo date('d M Y')?></p>
    <div class="table-responsive">
      <table class="table">
        <tr>
          <th style="width:50%">Total:</th>
          <td><?php $amount?></td>
        </tr>
      </table>
    </div>
  </div>
</div>
</div>

Here's my JavaScript code:

function PrintDiv() {    
   var divToPrint = document.getElementById('divToPrint');
   var popupWin = window.open('', '_blank', 'width=400,height=300');
   popupWin.document.open();
   popupWin.document.write('<html><body style="width: 58mm " onload="window.print()">' + divToPrint.innerHTML + '</html>');
    popupWin.document.close();
}

I've also included an image link for reference. I'm looking to print a compact receipt with limited height.

https://i.sstatic.net/4G3qb.png

Thank you.

Answer №1

Without seeing the inner div html and styles, it's difficult to determine.

One possible solution could be:

<body style="width: 58mm; height: 120mm; overflow: hidden;" onload="window.print()">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Calculate the percentage of the original height in relation to the document height

Is there a way to adjust the height of the document after new elements are added, without leaving excess space? I'm currently using the following code: $(document).ready(function() { var document_height = $(document).height(); document_height ...

What is the best way to transfer a variable from JavaScript to PHP?

I've been searching through numerous answered topics but I just can't seem to resolve the issue I'm facing. I'm utilizing a bootstrap date-time picker () and my objective is to pass the displayed value from a page containing the calenda ...

Enhancing React Native experience by dynamically editing array elements

This code block defines the state of my program, including an array: this.state = { arr: [{ arrid: 0, arrEmail: '', arrName: '', arrPhone: '' }], id: 0, email: "", isChecked: true, name: "", phon ...

Is there a way to modify text through post requests in Angular?

I am looking to send a post request to my Angular application and have the app change the text to a specific value upon receiving the request. I am eager to learn the process for accomplishing this task, particularly if it can be done using only Angular a ...

What steps are necessary to configure karma webdriver launcher to utilize my selenium server or grid?

Could someone assist in identifying what is causing the Karma javascript test runner to have issues connecting to and utilizing my selenium grid/server? I currently have a functioning selenium grid setup that I utilize with python selenium bindings for co ...

Issue with VueJS components not functioning as expected with routes

I've encountered an issue when using the component tag with an id of #app within the template of my components/App.vue file. Whenever I include this setup, I receive the following errors: // components/App.vue <template> <div id="app"> ...

A stylish flyout menu with a sleek li background in jquery

Experimenting with http://tympanus.net/Tutorials/CufonizedFlyOutMenu/, I decided to remove the fly-in descriptions and am now attempting to load the extra li with a style that will "highlight" the li.current-menu-item element. An object is set up as follo ...

Enhancing Website Performance with Vue.js 2.0 Lazy Loading

I'm attempting to implement Lazy Loading for my components in Vue.js 2.0 (within a Laravel 5.3 project). As per the guidelines, I should proceed like this: Vue.use(VueRouter); const Forum = resolve => require(['./Components/Forum/Forum.vue& ...

Automated line wrapping within a div

My goal is to showcase images within a unique div structure. Currently, the arrangement appears as follows: It seems that the green divs are extending beyond their parent div (the black one). This is how it's structured: <div class="photoView c ...

Incorporating text into the border without increasing the spacing

I managed to create a unique CSS shape using clip paths as the border of a div. However, I am now facing an issue where I cannot add text to this border without it getting cut off due to the way the shape was created (possibly because of overflow: hidden). ...

Could you please let me know how I can align underneath?

Image description can be found here Your assistance is greatly appreciated, as I am currently inexperienced with React and JavaScript. I am self-studying, so please excuse any basic questions. I have encountered a challenge with this issue. In the image ...

Ways to add margin-top to a card element without affecting the entire container-fluid

I'm attempting to change the background image of this container, but when I add margin-top to the card element, it shifts everything over the picture. Below is my Bootstrap4 code: #card.container-fluid { background-image: url("../images/picture2. ...

What are the distinct components used in CSS for :target?

I've encountered an issue with nesting :target pseudoclasses. Currently, I have a section containing an anchor tag. Right now, everything is functioning as intended; when I click on the anchor linking to #Current, it expands the area and displays the ...

The scope's attribute is present, but the variable within the scope's attribute is not

Currently, I am delving into angularJS development, but encountering a perplexing issue. I am attempting to format a JSON into a table with intricate rules. The JSON structure currently is as follows: { "id":"test", "title":"Test Sample", "de ...

The Google Location API allows you to access location-based services

Exploring the realm of Google Geolocation API has been an exciting journey for me. After obtaining my key, I dove into creating a straightforward form that prompts users to input a city name and then fetches the corresponding latitude and longitude using t ...

Changing the properties of the admin bar when it is hovered over in

After successfully styling a button on the admin bar, I noticed a few imperfections in the implementation. The button in question is situated on the admin bar and is labeled "maintenance". Upon clicking the button, jQuery triggers the addition of the clas ...

What is the process for transforming an AJAX request's onreadystatechange into a promise?

During the process of making a javascript AJAX request, I initially utilized the traditional callback approach to call the callback function within the onreadystatechange and retrieve all the values of readyState. However, upon switching my callback funct ...

"Troubleshooting problem with padding-right in Internet Explorer when displaying background image within

Encountering a problem with the IE browser (all versions up to IE 10). Here's the issue. The text in the input box is overlapping its background image. Unable to place this image in the parent div due to the dynamic nature of the input box and other ...

Variation in element widths and CSS widths

While inspecting an element in FF, it displays a width of 225px. However, the applied CSS sets the width to 207px for this element. The discrepancy may be due to Bootstrap and varying resolutions. Is there a tool available to identify chang ...

What is the best way to make the colored box reach all the way to the edges?

.output-container { background: #333; color: #fff; padding: 1rem 1; width: 100%; top: 0; z-index: 1000; text-align: center; } https://i.sstatic.net/V0RSm2ft.png W ...