Tips for printing several div elements with a set width and height without altering their size

At my workplace, we have perforated paper that employees fill out and cut to use as information cards. I am working on writing code using ASP.net core to input information onto these cards after a transaction. I have created a preview of the card in an HTML page, but when I try to print the page, the sizes of the divs do not match up with the actual perforated paper, causing alignment issues.

Here is the code for the preview page: Preview.cshtml

@model InputList
@{
    Layout = "_PrintLayout";
}
<div class="card" id="printCard">
    <div class="card-body pt-2">
        <div class="invoice">
           <table class="table m-b-30 table-borderless">
               <tbody>
                  @for(int i = 0; i < Model.Count(); i = i + 2)
                        {
                          <tr>
                              <td>
                                 <div class="card InputCard">
                                     <div class="card-header">
                                         test
                                     </div>
                                        <ul class="list-group list-group-flush">
                                            <li class="list-group-item">test test test</li>
                                            <li class="list-group-item">test test test test</li>
                                        </ul>
                                    </div>                                        
                                </td>
                                <td>
                                    @if (i+1 < Model.Count())
                                    {
                                    <div class="card InputCard">
                                        <div class="card-header">
                                            test 2
                                        </div>
                                        <ul class="list-group list-group-flush">
                                            <li class="list-group-item"> test2 test 2 test 2</li>
                                            <li class="list-group-item">test2 test 2 </li>
                                        </ul>
                                    </div>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        <div class="text-left d-print-none">
            <hr class="m-t-b-20">>
            <a href="javascript:window.print()" class="btn btn-outline-success m-r-5">
                <i class="fa fa-print m-l-5"></i> print
            </a>
        </div>
    </div>
</div>

Regarding the style: app.css

.InputCard {
    height: 15.82920199423rem !important;
    width: 21.9456027648rem !important;
    margin-bottom: 0.37080004671497rem !important;
    max-height: 15.82920199423rem !important;
    max-width: 21.9456027648rem !important;
    border-radius: 2px !important;
    border: 1px solid !important;
    box-shadow: none !important;
    -webkit-box-shadow: none !important;
    -moz-box-shadow: none !important;
}

Is there a way to print the preview page with accurate div sizes within the td block?

Answer №1

When utilizing the window.print() function to print a web page, the browser's printing feature is activated. In order to determine the layout of the printed document, it is necessary to identify the type of browser being used. Usually, when printing a web page through a browser, users have the option to adjust the margins on the paper.

To achieve desired printing results, consider accessing the browser's print preview and adjusting the Margins settings accordingly.

For reference, please view the screenshots provided below which demonstrate the process using Edge browser:

https://i.sstatic.net/dTiQK.png

https://i.sstatic.net/gPm24.png

Answer №2

To maintain the consistency of your website layout while optimizing for printing, it's recommended to create a separate print CSS using media query types. By doing this, you can tailor how the input card appears specifically for A4 paper size without disrupting the overall design and responsiveness of your site.
https://www.example.com/css/print-media-query-tutorial

@media print {
 .InputCard {
  height: 500px !important;
  width: 200px !important;
 }
}

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

switching the CSS class of a different child element from its parent

Having just started working with jQuery, I'm struggling to figure out how to target specific elements when clicking on toggle buttons. My goal is to toggle the class of each respective text container (from collapsed to expanded) when its correspondin ...

Add class or id dynamically when clicked

How can I dynamically change the CSS color of a roller-banner div based on user input? I have a codepen setup where I want to capture the class of the clicked element (e.g. colour3), and then apply that as an ID or class to the roller-banner div. Codepen ...

What techniques do platforms like Twitch, YouTube, Twitter, and Reddit use to dynamically load pages and update the URL without triggering a full reload?

Have you ever noticed that on some websites, when you click a link the page goes blank for a second and shows a loading indicator in your browser tab? However, on platforms like YouTube and Twitch, clicking a link smoothly transitions to the new page wit ...

React app frequently retrieves images from the server whenever react-router is being utilized

I am currently working on a create-react-app project that utilizes the react-router-dom. Within this project, I have several Components that function as pages in a Single Page Application. Each page includes the following component: return ( <im ...

Retrieve the value of a TextBox and display it as the title of a Tool

Hello there, I am currently learning front-end technologies and have a question. I would like to retrieve the value of a TextBox and display it in a Tool-tip. The code for the TextBox has a maximum length of 30 characters, but the area of the TextBox is no ...

Prop validation error: prop type mismatch occurred

My Vue.js countdown isn't displaying the values correctly. Despite defining everything as numbers, I keep getting an error in the console: [Vue warn]: Invalid prop: type check failed for prop "date". Expected Number, got String. I've gone th ...

Can you please explain the function of this JavaScript code for the Isotope filter?

I am struggling to grasp the functionality of a section of vanilla JS code related to the Isotope filter. You can find the original code here. var buttonGroups = document.querySelectorAll('.button-group'); for (var i = 0; i < buttonGroups.le ...

Issue with Chrome related to svg getScreenCTM function

Check out the jsFiddle demo I am attempting to utilize the getScreenCTM function to retrieve the mouse position based on SVG image coordinates. It seems to work in IE and Firefox, but not in Chrome. When I define the attributes width and height in the SV ...

Creating a scale effect similar to iCloud.com in Angular.JS: A step-by-step guide

Have you checked out the new icloud.com site? There's a cool effect on there that I want to try and recreate for a project I'm working on. When you go to and log in, you'll notice a loading gif followed by the calendar app scaling out to t ...

What is the method for adjusting the camera without being restricted by its axes?

I've modified some code from the example at to create a simplified version without certain elements like flying cubes and jumping: var camera, scene, renderer, controls; var objects = []; var raycaster; var moveForward = false; var moveBackward = fa ...

Modifying the appearance and behavior of an element dynamically as the page is being loaded using AngularJS

Struggling with a challenge for two days now, I have attempted to implement a panel-box using bootstrap and AngularJS. Within the confines of a controller, my code looks like this: <div id="menu2a"> <div class="panel list-group"> <div ...

React, incorporating emojis within a dropdown menu

Recently, I've been developing a small game using React where players can customize settings before beginning. The game involves four players chasing different tokens on the map while avoiding the player designated as "it". Within my code, I have a r ...

Toggle on and off using a checkbox feature in conjunction with the straightforward form gem

Seeking assistance in toggling an action using a checkbox on a post form. Not well-versed in javascript or JQuery. Struggling with this task while working alone. If anyone can provide guidance, it would be greatly appreciated! Using Rails 4.2.8 an ...

Create a CSS border that resembles the one used in Google's signup form

lies a curious inquiry: what unique border style is in play here? It rests slightly raised against the backdrop, creating an intriguing visual effect. After combing through various sources online, the answer still eludes me. Perhaps turning to Google' ...

What is the best way to provide an accessible title to an SVG icon using a tooltip in MUI?

When a tooltip is used with an icon button, the button automatically takes on the accessibility name of the tooltip title. This setup, as demonstrated in the documentation example, ensures that a screen reader announces it as "Delete, button", which is ben ...

Strategies for transferring a JavaScript variable from a JSP to a servlet

For my reporting module, I am utilizing the google visualization API java wrapper along with image charts. To pass the url of the generated chart to a servelet, I am using the getImageUrl() method to retrieve the url and storing it in a javascript variabl ...

What is the proper way to utilize a template literal within an import declaration?

Upon executing the following line: import stats from `./${process.env.STATS}` An error message is shown: Parsing error: Unexpected token ` To successfully load the module, use the following expression: const stats = require(`./${process.env.STATS}`) ...

Accordion jQuery failing to display tabs

I have a question about using 2 jQuery accordions with tabs inside them. Everything seems to be working, but when I try to expand the second accordion, the two tabs inside don't render properly. I'm not sure what the issue is. Any help on this wo ...

Step-by-step guide for integrating a Twig file in Symfony using Angular's ng-include feature

Seeking guidance in Angular, as a newcomer to the platform. I attempted to load a template within an ng-repeat loop like so, but encountered an error. I received the following error message: "Cross origin requests are only supported for protocol schemes ...

Unique Floating Bullet Icons Ascending When Enlarged

I'm currently trying to use a star image as a custom bullet point on an <li> element. However, I'm facing the issue where the bottom of the image aligns with the font's baseline, causing the image to be pushed upwards. Is there any sol ...