Невозможно загрузить HTML-изображение и теги холста в PDF в Angular 2 - PullRequest
0 голосов
/ 03 декабря 2018

У меня проблема с моим кодом.Мое требование - я хочу скачать HTML в PDF.Теперь я могу загружать такие тексты, как тег <p> и т. Д. Но я не могу загрузить теги изображения и холста в формате PDF.

Это мой dashboard.component.html

<div *ngIf="perAnaNoData == false" >
    <p id="content" #content style="text-align: center;font-size: 16px;" *ngIf="performanceAnalysisDrill == false">Performance Analysis (Recent 5 Test)</p>
    <img src="../../../assets/img/drillImage.png" *ngIf="performanceAnalysisDrill == false" style="height: 20px;width: auto;float: right;margin-right: 100px;" tooltip="Click on data labels to drilldown">
       <div style="height: 180px;width:400px;margin-left: 5%;"  *ngIf="performanceAnalysisDrill == false">
          <div style="display: block;">
               <canvas baseChart height="180" width="400"
                    [datasets]="performanceAnalysisBarData"
                    [labels]="performanceAnalysisBarLabels"
                    [options]="performanceAnalysisBarOptions"
                    [colors]="performanceAnalysisColors"
                    [legend]="performanceAnalysisBarLegend"
                    [chartType]="performanceAnalysisBarType"
                    (chartHover)="chartHovered($event)"
                    (chartClick)="performanceAnalysisDrillClicked($event)">
               </canvas>
           </div>
       </div>
</div>


<button (click)="downloadPDF()">Export to PDF</button>

А вот и мой dashboard.compoenet.ts file

import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';

....
....
import * as jsPDF from 'jspdf';

export class DashboardComponent implements OnInit,OnDestroy  {
  @ViewChild('content') content:ElementRef;

  public downloadPDF(){

     let doc = new jsPDF();

     let specialElementHandlers = {
          '#editor': function (element, renderer){
           return true;
           }
     };

  let content = this.content.nativeElement;

  doc.fromHTML(content.innerHTML,15,15, {
     'width':190,
     'elementHandlers': specialElementHandlers
  },
  function(downloadAsPDF){doc.save('saveInCallBack.pdf');});

  }
}

Я не знаю, как найти решение для его загрузки.Любой может помочь мне ...

1 Ответ

0 голосов
/ 03 декабря 2018

Я получил решение,

  public downloadPDF(){
       let pdf = new jsPDF();
       let options = {
          pagesplit: true
       };
       pdf.addHTML(this.content.nativeElement, 0, 0, options, () => {
          pdf.save("test.pdf");
       });

  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...