在Angular7中本地将图像(从外部库)保存到PDF文件?

在Angular7中本地将图像(从外部库)保存到PDF文件?,angular,typescript,angular7,Angular,Typescript,Angular7,我对Angular/Typescript语言不熟悉 我有一个qrcode img,它是从外部qrcode生成器库(angularx qrcode)生成的。我想有一个代码,允许用户生成此二维码,并将其保存为本地PDF文件 我提出了一个类似的问题,但必须将qrcode保存为PNG图像: 这是我从其他来源获得的代码: showPdf(parent) { const parentElement = parent.el.nativeElement.querySelector("img").sr

我对Angular/Typescript语言不熟悉

我有一个qrcode img,它是从外部qrcode生成器库(angularx qrcode)生成的。我想有一个代码,允许用户生成此二维码,并将其保存为本地PDF文件

我提出了一个类似的问题,但必须将qrcode保存为PNG图像:

这是我从其他来源获得的代码:

  showPdf(parent) {
    const parentElement = parent.el.nativeElement.querySelector("img").src;
    console.log(parentElement);
    const pdfInBase64 = parentElement;
    const newBlob = new Blob([pdfInBase64], {type: 'application/pdf'});
    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
      window.navigator.msSaveOrOpenBlob(newBlob); // For IE browser
    }
    const linkElement = document.createElement('a');
    const url = URL.createObjectURL(newBlob);
    linkElement.setAttribute('href', url);
    linkElement.setAttribute('download', 'sample.pdf');
    const clickEvent = new MouseEvent('click', {
      'view': window,
      'bubbles': true,
     'cancelable': false
    });
    linkElement.dispatchEvent(clickEvent);
  }
此代码允许我下载PDF文件,但当我尝试在adobe上查看该文件时,错误显示:“adobe无法打开该文件,因为它不是受支持的文件类型,或者因为该文件已损坏”

有人能帮我吗?非常感谢你