Skip to content

screen is flashing while use import html2pdf from 'html2pdf.js' in react #846

@xLazaki

Description

@xLazaki

I am trying to use

export const downloadPDF = (html, filename) => {
  const style = document.createElement('style')
  style.innerHTML = `
   body {
    position: fixed !important;
    top: -99999px !important;
    left: -99999px !important;
    z-index: -99999 !important;
    }
  `
  document.head.appendChild(style)
  html2pdf().set(
    {
      jsPDF: { format: 'a4', unit: 'mm' },
      image: { type: 'jpeg', quality: 1 },
      margin: -0.1,
    },
  ).from(html).save(filename).finally(() => {
    style.remove()
  })
}

This function prints my HTML. When I call this function, my screen shows the HTML I fixed by rendering it on the outer screen, but it's still showing a white screen before removing the style at the final callback
Does anyone have a solution to solve this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions