I have running Angular 12 application and I am integrating the behavior to print report. I am able to achieve the print on button click which opens a new window, but I am not able to figure out how to achieve below things:

<img src="assets/images/galaxy.png" alt="">, the image is not getting displayed in the print window. If I comment window.print() and just use window.open(), image is getting displayedprint.service.ts
showDialog() {
const factory =
this.componentFactoryResolver.resolveComponentFactory(PrintReportComponent);
const dialogComponentRef = factory.create(this.injector);
dialogComponentRef.instance.title = 'Report';
dialogComponentRef.changeDetectorRef.detectChanges();
//fetch the root DOM element of ModalComponent
const domElement = (dialogComponentRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
const WindowPrt = window.open(
'',
'',
'top=0,left=0,height=100%,width=auto'
);
WindowPrt.document.head.innerHTML = document.head.innerHTML;
WindowPrt.document.body.innerHTML = domElement.outerHTML;
WindowPrt.document.close();
WindowPrt.focus();
WindowPrt.print();
WindowPrt.close();
}
stackblitz link: https://stackblitz.com/edit/angular-ivy-c1ewya?file=src%2Fapp%2Fprint.service.ts
In this part :
const WindowPrt = window.open(
'',
'',
'top=0,left=0,height=100%,width=auto'
);
You have to remove '', ''.
change to :
const WindowPrt = window.open(
'top=0,left=0,height=100%,width=auto'
);
You should change your strategy at all. If you will do this, it will work. Please try this example one:
I added one dummy image in it and it is displayed.
Good luck ;)