angular2 html2 может распечатать документ на другой странице или удалить его с текущей страницы после печати

Доброе утро,

Я использую html2canvas для печати документа, но я хочу напечатать документ на новой пустой странице или удалить предварительный просмотр, который появляется на текущей странице браузера после загрузки документа.

Вот как выглядит шаблон:

<div class="container-fluid">
    <div class="here" (click)="pdfHtml()">
        <div style="width: 100%; height: 100%;"  #test>
            ...content...
        </div>
    </div>
</div>

И файл TS это:

import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
import * as jsPDF from 'jspdf';
import * as html2canvas from 'html2canvas/dist/html2canvas';

@Component({
  selector: 'app-report-registration',
  templateUrl: './report-registration.component.html',
  styleUrls: ['./report-registration.component.css']
})
export class ReportRegistrationComponent implements OnInit {

   visible = true;
@ViewChild('test') el: ElementRef;
isClassVisible: true;

  constructor( private route: ActivatedRoute,private router: Router) {}

  ngOnInit() {}

  public pdfHtml() 
    {
        this.visible = false;
        let pdf = new jsPDF();
        let options = {
            pagesplit: true,
            html2canvas: this.test()
        };


        pdf.addHTML(this.el.nativeElement, 0, 0, options, () => {

            pdf.save("registration.pdf");
        });
    }

    test()  {
          html2canvas(document.body.getElementsByClassName('here')).then((canvas) => {
          document.body.appendChild(canvas);
        });

    }

}

Как это сделать?

0 ответов

Другие вопросы по тегам