crazecoder / open_file

A plug-in that can call native APP to open files with string result in flutter, support iOS(UTI) / android(intent) / PC(ffi) / web(dart:html)
BSD 3-Clause "New" or "Revised" License
253 stars 438 forks source link

Openning PDF in iOS #147

Closed djireland closed 2 months ago

djireland commented 3 years ago

I'm trying to open a PDF file that is local to the device on IOS 12. The PDF doesn't open but rather an action dialog box opens (attached) instead. Can we open the PDF directly ?

Here is the code I'm using:

     OpenFile.open(report.path,  type: "application/pdf", uti: "com.adobe.pdf");

and pubspec.yaml

 open_file: ^3.2.1

Thanks!

Simulator Screen Shot - iPhone 12 - 2021-05-21 at 13 56 46

webnickell commented 3 years ago

I have same issue

Allyanora commented 3 years ago

I'm having the same issue for any kind of file on iOS, not just pdf.

Android also opens this dialog to choose with what program to open and after selection and then the files are opened as expected.

crazecoder commented 3 years ago

If you are using a simulator, try it on a real machine

webnickell commented 3 years ago

If you are using a simulator, try it on a real machine

Oh no, we check it on different real IOS devices, this problem is not in simulator.

crazecoder commented 3 years ago

I've tried it and it works, Make sure your PDF files are in the app's sandbox, Maybe that's the reason

ygotthilf commented 3 years ago

I have the same issue.

I found out the issue happens when the file extension is not '.pdf' even if Uti and Type are set.

I can reproduce the issue by using the flutter_cache_manager library that add a .file extension by default.

Hope it helps.

ygotthilf commented 3 years ago

The (ugly) workaround I found for the old ".file" files still in cache looks like:

    String path = file.path;

    if (path.endsWith('.file')) {
      final copied = await file.copy(
        path.replaceFirst(RegExp(r'\.file$'), '.pdf'),
      );

      path = copied.path;
    }

    await OpenFile.open(
      path,
      type:  'application/pdf',
      uti:  'com.adobe.pdf',
    );