0

i have a button which contains<p:printer> tag, when i press the button it opens the print page contains only barcode but it appear with header and footer. i tried to use css margin:0; size:auto it removes header and footer of the page before pressing the button. i need to remove the header and footer after pressing button

            <h:outputText value="#{commonLabels['outputLable.document.code']}" />
            <p:barcode id="barcodeid"  type="code128" value="1234567890123456" style="position:relative; bottom: 30px ; margin-left: 50px;" class="dataTableClassName"/>

        </p:panelGrid>

        <p:commandButton id="acceptBtnId" style="margin-left: 4px" class="two_button_right"   value="#{commonLabels['button.print']}" update="searchForm"
                         process="@this">
            <p:printer target="barcodeid"/>
        </p:commandButton>

        <p:commandButton id="closeBtnId" class="two_button_right"   value="#{commonLabels['button.close']}"
                         process="@this"  oncomplete="PF('accept_dialog').hide();" />

enter image description here

Ahmed Ali
  • 3
  • 2
  • 2
    The technical printing is not a PrimeFaces thing, it is a browser thing, the javascript generated by the `p:printer` tag just does a `document.print()` in javascript (check the source). So it is the browsers that adds the header and footer in addition to the client side html (not xhtml)... So search for a browser generic solution. Hint: You canot force this from an html page. Only solution is to create a server side document like a pdf and have the use print that. – Kukeltje Jul 26 '20 at 13:44
  • Hmmm so you **can** (sort of) force it nowadays – Kukeltje Jul 26 '20 at 16:47
  • its required html page , can`t be pdf .. in addition to i don`t want the client to press ctrl+p because i want to print only barcode not the full page .. all css solutions didn`t work for me it affects the page not the barcode. – Ahmed Ali Jul 28 '20 at 07:46
  • ??? What header and footer do you mean then? If you don't mean the page/browser header and footer, your question is totally unclear. – Kukeltje Jul 28 '20 at 09:00
  • its browser`s header and footer , after i click a button it display a barcode but with header and footer. the css affects the page with the button not the displayed barcode page. – Ahmed Ali Jul 28 '20 at 13:55
  • How about using a CSS media query for print so you don't influence the button when shown in the browser? Something like `@media print { body { margin: 0; size: auto; } }`. – SaschaM78 Jul 28 '20 at 14:50

0 Answers0