Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
How to hide background contents of window.open while printing in Angular

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:

  1. Remove background contents on window.open so that the print window looks like a normal print window which we see by pressing Win+P in our browser. enter image description here
  2. Center the print window popup in the screen.
  3. Not able to display images in print window. If I add any img tag in html like: <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 displayed

print.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

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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'
        );
about 4 years ago · Juan Pablo Isaza Relatório

0

You should change your strategy at all. If you will do this, it will work. Please try this example one:

link-stackblitz

I added one dummy image in it and it is displayed.

Good luck ;)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda