我必须生成一个PDF文件与我的Angular 组件的视图.我使用domtoimage
将组件呈现为PNG图像,使用jsPDF
将生成的图像添加到PDF.
But in rendered PDF I noticed some gray stripes (the half of the text was hidden because it's a special effect in my application, it's not a bug):
它们不存在于我截图的原始组件中.
如何go 除这些条纹?
以下是我生成PDF的代码:
openPDF(): void {
this.generatingPDF = true;
const DATA = this.textContainerRef.nativeElement!;
domtoimage
.toPng(DATA)
.then((png) => {
const w = DATA.clientWidth;
const h = DATA.clientHeight;
const hpng = (h / w) * 190;
const doc = new jsPDF('p', 'mm', 'a4');
try {
let name = 'untitled_text';
if (this.text?.title) {
name = this.text.title;
}
doc.addImage(png, 'png', 10, 10, 190, hpng, 'SLOW').save(name);
this.generatingPDF = false;
this._cdr.markForCheck();
} catch (e) {
this.generatingPDF = false;
this._cdr.markForCheck();
}
})
.catch((err) => console.log(err));
}