DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.16k stars 1.91k forks source link

File not in pdf format #659

Open riccardopirani opened 6 years ago

riccardopirani commented 6 years ago

Hi I have an exception with the code below I have to visulize a pdf file generated by a base64 in the android filesystem, but when you run the pdf view I have the exception below. What can be due? and how can I solve? (Gradle is: implementation 'com.github.barteksc:android-pdf-viewer:2.8.2')

Exception: load pdf error java.io.IOException: can not create document: File not in PDF format or corrupted. at com.shockwave.pdfium.PdfiumCore.nativeOpenDocument (Native Method)

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE " />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

Java Android Code:

  byte[] bytes = base64Rapportino.getBytes();
    FileOutputStream os = openFileOutput("mydemo.pdf",MainActivity.contextOfApplication.MODE_PRIVATE);
    os.write(bytes);
    os.close();
    System.out.println("\n generate pdf");
    try {
    File directory = MainActivity.contextOfApplication.getFilesDir();
    System.out.print("\n Directory Path: "+directory.getAbsolutePath());
    File file = new File(directory, "mydemo.pdf");
              pdfView.fromFile(file).load();
    }
    catch (Exception ex){
      Support.Notification(GestioneRapportiniActivity.this, "Errore", "Apertura file: "+ex);
     }
anilejder commented 4 years ago

Same here.

Did you find any solution? @riccardopirani

riccardopirani commented 4 years ago

@anilejder No currently the company I'm working with has decided to rewrite the app in flutter.