Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print page with Angular 5

Tags:

Does anybody of you know how it's possible to print a section of my website using Angular 5? I tried finding a solution on the internet, but it seems to me that there are only solutions available for Angular.

like image 601
reschandreas Avatar asked Apr 13 '18 17:04

reschandreas


People also ask

How to print a page in Angular?

To print the document, use the print method from document editor instance. Refer to the following example for showing a document and print it. import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { AppModule } from './app.

What is @media print?

Print media is one of the oldest and basic forms of mass communication. It includes newspapers, weeklies, magazines, monthlies and other forms of printed journals. A basic understanding of the print media is essential in the study of mass communication.

What is print JS?

Print. js was primarily written to help us print PDF files directly within our apps, without leaving the interface, and no use of embeds. For unique situations where there is no need for users to open or download the PDF files, and instead, they just need to print them.


1 Answers

There is 2 ways you can do it. 1. using print-js

npm install print-js

add the script route to the angular-cli.json

"../node_modules/print.js/src/index.js"

add the print functionality to the html file

<div class="welcome-screen-wrapper-new-test">
  <div class="welcome-screen-header" id="what-needs-to-be-printed-page">

printing section goes here

 </div>
  <div class="new-test-print">

onClick function goes here

 <div class="print-wrapper" onclick="printJS('print-page', 'html')">
      <span class="icon print"></span>
    </div>
  </div>
</div>

DONE!

  1. Insert this script tag

<script src="https://printjs-4de6.kxcdn.com/print.min.js"></script>

Add use the same html format.

GOODLUCK!

like image 193
stacksonstacksonstacks Avatar answered Oct 11 '22 13:10

stacksonstacksonstacks