0

I am using React Native v0.67.2 and looking to generate PDF from HTML using react-native-html-to-pdf. This is the function I use to generate the PDF, but the location of generated Pdf isn't showing in the iOS file manager.

const createPDF = async () => {
  let options = {
    html: '<h1>PDF TEST</h1>',
    fileName: 'testFile',
    directory: 'Documents',
  };

  let file = await RNHTMLtoPDF.convert(options);

  // console.log(file.filePath);
  alert(file.filePath);
}

The file exists in an unknown location, but I'm expecting the downloaded PDF file in the 'Documents' directory of iPhone Files. How do I move the PDF to this location and resolve this issue?

Thank you in advance.

Mir Stephen
  • 1,758
  • 4
  • 23
  • 54

1 Answers1

0

Duplicate of: pdf created by react native html to pdf is not showing in provided path

On IOS you can only use that Documents path that you already have. You cannot make it save anywhere else.

Directory where the file will be created (Documents folder in example above). Please note, on iOS Documents is the only custom value that is accepted.

Ref: https://github.com/christopherdro/react-native-html-to-pdf#options

Obsidianlab
  • 667
  • 1
  • 4
  • 24
  • Thank you, I did as stated and used `directory: 'Documents'` in options but still it isn't generating the file there. – Mir Stephen Apr 20 '22 at 17:56
  • It is generating the file there though It's generating it under the directory of the app. Seems like with this package You cannot save outside of the RN app directory. If my answer help don't forget to Mark it as your accepted answer. I would see if you can try to use another package that does allow the correct directory since this one has been updated in a while. – Obsidianlab Apr 20 '22 at 18:17
  • Thank you for your time, I have seen some videos of its previous versions, and people have done it. There must be some workaround for it. I will share my experience if I found the solution. – Mir Stephen Apr 20 '22 at 18:31