Print dynamic query

Asked

Viewed 63 times

0

I have a query in a system where the user selects the month and the corresponding records are shown on the same page. I want to print the result of the query but how the form sends via GET:

<form action="" method="get" id='form-contato' class="form-horizontal col-md-10"> 

I can’t send to another page and assemble the pdf to print. There is a way to send the query result in an Array and call the file "print.php"?

Remembering that this query changes with each choice of a new month.

inserir a descrição da imagem aqui

1 answer

0

You can use CSS to determine the areas you want to print, and create a button, which by clicking it calls the method print.

See the example below.

$("#print_page").on("click", function(){
  window.print();
});
<!DOCTYPE html>
<html>
<head>
  <title>Imprimir área desejada</title>
  <style type="text/css">
    @media print {
      * {
        visibility:hidden;
      }
      .imprimir {
        visibility: visible;
        position: absolute;
        top:0;
        left:0;                                     
      }                                  
    }
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
  <strong>Isto não vai ser impresso!</strong>  
  <div class="imprimir">
      Já isto e, apenas isto, será impresso!
      <input type="button" id="print_page" value="IMPRIMIR" />
  </div> 
  Aqui também não vai sair na impressão!            
</body>
</html>

  • When I click the button nothing happens... where did I miss? I inserted the CSS , I declared the function I created the DIV and the button but nothing happens. Even so thank you, it is already a way to be followed.

  • Maybe you’ve forgotten the jQuery add to your html <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  • I declared jQuery unsuccessfully.

  • I don’t understand what you mean!

  • Unsuccessful means it didn’t work. I assume since it’s an http, I don’t have to send jquery to the server, no?

  • You can do so on the button, without jquery: <input type="button" value="IMPRIMIR" onclick="window.print();" />

  • Thanks Wellingthon, I’ll try in a little while, thank you very much.

  • Solved, thank you very much.

  • If possible, accept the answer, so the question is as solved, in addition to improving more and more the quality of the site.

  • Sorry Wéllingthon, I don’t know how to accept the answer...

Show 5 more comments

Browser other questions tagged

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