cap-pdf-file-opener
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

cap-pdf-file-opener

This plugin is built on capacitor platform to open PDF files on android devices

Usage: npm i cap-file-opener

this is sample code that generates pdf using pdfmake and opens it using this plugin

  const fileName = 'file.pdf';
  try {

    pdfmake.vfs = pdfFonts.pdfMake.vfs;

    const doc = pdfmake.createPdf({ content: 'Hi. I am a PDF.' });
    doc.getBase64((base64data) => {

      Filesystem.writeFile({
        path: fileName,
        data: base64data,
        directory: FilesystemDirectory.External
       
      }).then((writeFileResult) => {
        Filesystem.getUri({
          directory: FilesystemDirectory.External,
          path: fileName
        }).then((getUriResult) => {
        
          const path = getUriResult.uri;
          
          Plugins.CapFileOpener.open({ filePath: path.substr(7), fileMediaType: 'application/pdf' });

        }, (error) => {
          console.error('Error while opening pdf', error);
        });
      });
    });
    } catch (error) {
    console.error('Unable to write file', error);
  }

In the generated android project, in Mainactivity.java, add the following line.

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
  add(CapFileOpener.class);
}});

Readme

Keywords

Package Sidebar

Install

npm i cap-pdf-file-opener

Weekly Downloads

10

Version

0.0.5

License

MIT

Unpacked Size

473 kB

Total Files

63

Last publish

Collaborators

  • reddysuresh78