Invalid Format of "filename.pdf" when we open it on success of WriteFile Api

On success of this WriteFile API it generates a .pdf file.
but when I open it through fileOpener or I open it manually while going it into that directory it gives me error that test.pdf is of Invalid Format

When I generate .docx file or .txt file it is opening and displaying the data.

this.file.writeFile(cordova.file.externalDataDirectory,"test.pdf","HEllO WORLD",true).then(succ=>{
      console.log("File write success : ", succ)
    ).then((success) => {
      console.log('success open file: ', success);
    }, (err) => {
      console.log('error open file', err);

      console.log(" write File error : ", err)

I am facing this issue.

What is this? Provide a link to the library (and Ionic Native plugin if this is one).

I have imported File from ionic-native

import { File } from '@ionic-native/file';

Constructor defined for the File API

 private file: File

So in this.file.writeFile i am accessing the File api.



Okay, then it is quite clear: You can just write plain text to a PDF file, PDF is a binary format.
Try to open a working PDF file in Notepad (or your favorite editor) to see what this means.

Other files are opening of .pdf format.

Only the .pdf file which I am creating and opening from Ionic File Api is not opening.

It gives error.


Yes, see what I wrote again: You can’t just create a PDF using writeFile. You can only create plain text files with that or if you replace the “HEllO WORLD” with the required binary format of PDF.