ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
50.89k stars 13.52k forks source link

feat: Ability to print more than 1 page of content #19886

Open cjorasch opened 4 years ago

cjorasch commented 4 years ago

Feature Request

Ionic version: [x] 5.0.0-beta.0

Describe the Feature Request If you print a page that contains more content than will fit on a single printed page then only one page will be printed and a scroll bar will be printed on that page. The content will be clipped to the single page.

Use cases:

Describe Preferred Solution It should be possible to print across multiple pages.

Use @media print settings to changing scrolling behavior during printing.

martinmitteregger commented 4 years ago

Are there any updates or plans to support printing by css @media print of more than one page?

ugenu commented 3 years ago

@martinmitteregger, @cjorasch

Possible solution

I have successfully achieved printing more than one full page by doing the following:

  1. Changing the App.vue template to

    <template>
    <ion-router-outlet />
    </template>
  2. Adding these @media print css styles

    @media print {
    body {
    position: initial!important;
    max-height: initial!important;
    overflow: auto!important;
    }
    
    ion-router-outlet {
    overflow: auto!important;
    contain: none!important;
    position: initial!important;
    }
    }
  3. Making sure my printable content follows the proper guidelines, no overflow hidden, etc.

Result

Here is the result: surpasses my expectations and looks just as amazing online as it does in pdf

Text, badges, buttons Card and lists

Print testing was doing via html-pdf-node

Explanation

ion-app, ion-page, ion-content uses shadow elements and containing styles, by using a bare-bones layout we can skip the headache. There may be other css styles to get those elements to render properly, but this is good enough for my solution!

brainboutique commented 1 year ago

In case anyone faces similar issue: On Angular I had to add following to global.scss to make it print acceptable - see the add-on on ion-content:

@media print {
  .ion-page {
    display: initial !important;
    position: initial !important;
  }
  body {
    position: initial !important;
    max-height: initial !important;
    overflow: auto !important;
  }
  ion-router-outlet {
    overflow: auto !important;
    contain: none !important;
    position: initial !important;
  }
  ion-content {
    --offset-bottom: unset !important;
    display: unset !important;;
    position: unset !important;;
  }
}
Gkleinereva commented 3 months ago

I couldn't get @brainboutique's solution to work in our application that uses <ion-tabs> elements to support tabbed navigation. I would love it if anyone has suggestions for adapting it!

It would be awesome if Ionic could incorporate more accommodating print styles into their inbuilt components by default!