2

Is there a way to describe a printable document (A4 size for instance) using HTML/CSS ? In HTML5 we have <header>, <footer>, and plenty of elements which can be used for building a document, but I wonder if I can output PDF documents where content is displayed using web technologies.

I try using media query @print in CSS in order to output a HTML file as PDF using my browser print box, but this solution is not so good in my point of view (displaying page number, or footnotes in footer).

Furthermore the render is not the same using different browser, and I want my documents to be all the same.

Canuto-C
  • 391
  • 2
  • 7
  • 17

1 Answers1

4

@print is the best solution:

@media print {
    body * {
        visibility: hidden;
    }
    #section-to-print, #section-to-print * {
        visibility: visible;
    }
    #section-to-print {
        position: absolute;
        left: 0;
        top: 0;
    }
}

See all posible solutions here: Print <div id=printarea></div> only?

You will probably find what you need.

Community
  • 1
  • 1
  • Thank you for your comment Luka, I already know this solution and I just wonder if there no other way to make it work. – Canuto-C Dec 15 '16 at 09:54