How to load PDFs host with google drive or dropbox ?

Good day,


I have been using the Syncfusion Flutter Pdf Viewer for the last few days.
I am just struggling to load PDFs hosted with google drive or Dropbox.

string URL = "https://www.syncfusion.com/downloads/support/directtrac/general/pd/GIS_Succinctly353717706.pdf"; loads perfectly but
string URL = "https://drive.google.com/file/d/1RaM7eOiwLG3dbawaOFsQoR_nl9jtUpPK/view?usp=sharing"; doesn't load.

3 Replies

DR Deepika Ravi Syncfusion Team August 18, 2022 02:27 PM UTC

Hi Evans,


We were able to reproduce the reported issue in our end. When loading the provided PDF URL in our SfPdfViewer it throws an exception "The loaded PDF file is corrupted or damaged". We initially thought that the shared PDF was corrupted, but to confirm we checked loading various other PDF files from Google Drive in our SfPdfViewer and faced the same issue. Then, we prepared a sample without our SfPdfViewer, where we read the PDF file from Google Drive using http package and then saved it and opened that PDF file in the Adobe Reader - Mobile using open_file package (which is used to view the PDF document in the default PDF Viewer). Even in Adobe Reader - Mobile, we faced the same corrupted file issue. We are currently checking on this and will update the further details on August 22, 2022.


Please find the reference sample code snippet that we tried without our SfPdfViewer and the Adobe Reader screenshot from below,


Code Snippet:


//Get the external storage directory

Directory directory = (await getApplicationDocumentsDirectory());

 

//Get the directory path
final String path = directory.path;

 

//Create an empty file to write the PDF data
File file =
File('$path/output.pdf');


final Uint8List _documentBytes =
await http.readBytes(Uri.parse('http://drive.google.com/file/d/1RaM7eOiwLG3dbawaOFsQoR_nl9jtUpPK/view?usp=sharing%22'), );

 

//Write the PDF data
await file.writeAsBytes(_documentBytes.toList(),);

 

//Open the PDF file in default mobile PDFViewer
OpenFile.open(
'$path/output.pdf'); // Open-source library to launch the PDF file in mobile devices

 


// Adobe Reader Output Screenshot


https://www.syncfusion.com/downloads/support/directtrac/general/MicrosoftTeams-image1975372025.png


Regards,

Deepika Ravi



DR Deepika Ravi Syncfusion Team August 23, 2022 02:14 AM UTC

Hi Evns,


Sorry for the inconvenience.


We are checking on this and will update the further details on August 24, 2022.


Regards,

Deepika R



DR Deepika Ravi Syncfusion Team August 24, 2022 08:16 AM UTC

Hi Evans,


On further analysis, we found that the document bytes retrieved from the http package are not proper, which returns document type html data, so when loading the Google Drive URL , it throws an exception [“The loaded PDF file is corrupted or damaged]. We did some search and found the workaround to resolve the issue, kindly change the URL link in this format [https://drive.google.com/uc?export=view&id=<FILE_ID>] and then load the URL in the SfPdfViewer.network constructer. The following code example explains the same.


Code snippet:


class _HomePage extends State<HomePage> {
 
@override
 
Widget build(BuildContext context) {
   
return Scaffold(
      appBar:
AppBar(title: const Text('Syncfusion Flutter PDF Viewer')),
      body:
SfPdfViewer.network(
          
'https://drive.google.com/uc?export=view&id=1RaM7eOiwLG3dbawaOFsQoR_nl9jtUpPK'),
    );
  }
}

 


Reference link: https://stackoverflow.com/questions/59849232/display-images-from-google-drive-using-networkimage


The above mentioned suggestion is the one way of workaround solution for resolve the issue .Please let us know If you need a sample with authentication and then accessed Google drive, retrieves PDF data using Google Drive APIs, and then loads that data into SfPdfViewer.


Regards,

Deepika Ravi


Loader.
Up arrow icon