简体   繁体   中英

How do I export the data rendered by react component to pdf?

I have a component view which has images, tables, and list styled with CSS. Is there a legit approach to export/save that view to pdf? ctrl+p doesn't really work because it grabs the entire page with navigation etc. I'm thinking to implement print button which will redirect to another "PrintComponentCleanView" and from there do ctrl+p . This is a 2 step process. I'm sure there is a better approach to accomplish this. Any ideas appreciated.

Adding print styles in your existing stylesheet:

@media print
{
  .navbar {
    display: none;
  }
  ...
}

Adding a different stylesheet for printing:

<link rel="stylesheet" type="text/css" media="print" href="style.css">

You can then use window.print(); for opening up the Print dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM