react-to-print: documentTitle doesn't seem to work

Using react-to-print v2.11.0

<ReactToPrint
   documentTitle='some title'
   trigger={() => (
      <Button
         primary
         size='small'
      >
         Export
      </Button>
    )}
    content={() => this.someRef}
/>

when choosing to save download as PDF, the default document name is still the page title, not the one specified in documentTitle prop

also using react helmet v5.2.1 to set the page title at render, not sure if it impacts anything

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@MatthewHerbst I’m on v2.14.1 and even in the Codesandbox example (which uses v2.14.1 as well) documentTitle doesn’t work: Screenshot from 2021-11-23 09-32-35

Update: I figured out it’s because the app would run in an iframe (Storybook for my development, and in Codesandbox it also runs in an iframe) and apparently that prevents setting the main window title. When opening the component in Storybook/Codesandbox in its own window, it works 🎉 I guess that solves it for me, as I only use Storybook for some component development while the production app doesn’t run in an iframe.

Hi, I am having a similar issue, documentTitle works for chrome, not for firefox or safari. I tried to change document.title using useEffect or onBeforePrint, the title is changed but the printer doesn’t pick up the name. For firefox and Safari, the default name is still “Untitled”.