<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KingEricx</title>
    <description>The latest articles on DEV Community by KingEricx (@kingericx).</description>
    <link>https://dev.to/kingericx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F869167%2F1d42bbfa-42af-46ce-829e-4d2fc3468222.jpg</url>
      <title>DEV Community: KingEricx</title>
      <link>https://dev.to/kingericx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kingericx"/>
    <language>en</language>
    <item>
      <title>Removing print button from your online receipt using @media print</title>
      <dc:creator>KingEricx</dc:creator>
      <pubDate>Sat, 28 May 2022 13:37:06 +0000</pubDate>
      <link>https://dev.to/kingericx/removing-print-button-from-your-online-receipt-using-media-print-2pp6</link>
      <guid>https://dev.to/kingericx/removing-print-button-from-your-online-receipt-using-media-print-2pp6</guid>
      <description>&lt;p&gt;In this article, you will learn how to remove a "print button" from an online document or receipt. But first, you need to learn how to use the JavaScript(Js) print command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Designing the document or receipt
&lt;/h2&gt;

&lt;p&gt;First, we have to write the HTML to print the document or receipt,  I will be using a table to show a receipt-like content in a nicely formatted way.&lt;br&gt;&lt;br&gt;
Here is the code snippet for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Receipt Demo&amp;lt;/title&amp;gt;
    &amp;lt;style type="text/css"&amp;gt;
        * {
            font-size: 12px;
            font-family: 'Times New Roman';
        }

        td,th, tr,table {
            border-top: 1px solid black;
            border-collapse: collapse;
        }

        td.description,th.description {
            width: 75px;
            max-width: 75px;
        }

        td.quantity,th.quantity,td.price,th.price {
            width: 40px;
            max-width: 40px;
            word-break: break-all;
        }

        .centered {
            text-align: center;
            align-content: center;
        }

        .ticket {
            width: 155px;
            max-width: 155px;
        }

        @media print {
            .hidden-print,.hidden-print * {
                display: none !important;
            }
        }
    &amp;lt;/style&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;div class="ticket"&amp;gt;    
            &amp;lt;p class="centered"&amp;gt;RECEIPT EXAMPLE
                &amp;lt;br&amp;gt;Address line 1
                &amp;lt;br&amp;gt;Address line 2&amp;lt;/p&amp;gt;
            &amp;lt;table&amp;gt;
                &amp;lt;thead&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;th class="quantity"&amp;gt;Q.&amp;lt;/th&amp;gt;
                        &amp;lt;th class="description"&amp;gt;Description&amp;lt;/th&amp;gt;
                        &amp;lt;th class="price"&amp;gt;$$&amp;lt;/th&amp;gt;
                    &amp;lt;/tr&amp;gt;
                &amp;lt;/thead&amp;gt;
                &amp;lt;tbody&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;td class="quantity"&amp;gt;1.00&amp;lt;/td&amp;gt;
                        &amp;lt;td class="description"&amp;gt;WHITE CREATIVITY HANDBOOK&amp;lt;/td&amp;gt;
                        &amp;lt;td class="price"&amp;gt;$25.00&amp;lt;/td&amp;gt;
                    &amp;lt;/tr&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;td class="quantity"&amp;gt;2.00&amp;lt;/td&amp;gt;
                        &amp;lt;td class="description"&amp;gt;SWEETS&amp;lt;/td&amp;gt;
                        &amp;lt;td class="price"&amp;gt;$5.00&amp;lt;/td&amp;gt;
                    &amp;lt;/tr&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;td class="quantity"&amp;gt;1.00&amp;lt;/td&amp;gt;
                        &amp;lt;td class="description"&amp;gt;FANS&amp;lt;/td&amp;gt;
                        &amp;lt;td class="price"&amp;gt;$10.00&amp;lt;/td&amp;gt;
                    &amp;lt;/tr&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;td class="quantity"&amp;gt;&amp;lt;/td&amp;gt;
                        &amp;lt;td class="description"&amp;gt;TOTAL&amp;lt;/td&amp;gt;
                        &amp;lt;td class="price"&amp;gt;$40.00&amp;lt;/td&amp;gt;
                    &amp;lt;/tr&amp;gt;
                &amp;lt;/tbody&amp;gt;
            &amp;lt;/table&amp;gt;
            &amp;lt;p class="centered"&amp;gt;Thanks for your purchase!
                &amp;lt;br&amp;gt;Legends Only&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;button id="btnPrint" class="hidden-print" onclick="window.print()"&amp;gt;Print&amp;lt;/button&amp;gt;      
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: We have used the "window.print()" command on-click of the print button, to trigger the printing dialog box. This is a static example, you can always use a framework (client side or server side) to render the content in a dynamic way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hiding the button
&lt;/h2&gt;

&lt;p&gt;In CSS media query allows you to determine a different style for your HTML element under different scenarios, for example, @media screen helps you write CSS for different screen sizes, to hide our print button, we will be using @media print, which allows us to set a style for out HTML element while we are printing.&lt;br&gt;
We have set the CSS display property of our print button to “none”  within the @media print query which is used to hide the button when we print the document/receipt.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
