binSaed / flutter_cached_pdfview

Enhanced PDF view for Flutter.
https://pub.dev/packages/flutter_cached_pdfview
MIT License
121 stars 70 forks source link

Unable to Open the Shared File of Google drive #58

Closed sumitzartek closed 3 years ago

sumitzartek commented 3 years ago

Describe the bug I have create your sample project clone and then after I tried to view the PDF This One : https://drive.google.com/file/d/1GkgKDPjtnv-WXd8k0Jc1y6su20RFnZy6/view?usp=sharing I was unable to View.

Is there any way to do this : So please tell me PDF( swipeHorizontal: true, ).cachedFromUrl( 'https://drive.google.com/file/d/1GkgKDPjtnv-WXd8k0Jc1y6su20RFnZy6/view?usp=sharing'), )

Desktop (please complete the following information):

binSaed commented 3 years ago

hi @sumitzartek this google drive link will not work because this not a download link now I making a helper method that's will help u to get a download link

binSaed commented 3 years ago

use this method to get a download link from the google drive link

String getDownloadLinkFromDrive(String driveLink) {
  final fileId = RegExp(r'/d\/(.+?)(?:\/|#|\?|$)$')
      .stringMatch(driveLink)
      .split('/')[2];
  if (fileId == null) return driveLink;
  return 'https://drive.google.com/uc?export=download&id=$fileId';
}

use it like this

      PDF(
        swipeHorizontal: true,
      ).cachedFromUrl(getDownloadLinkFromDrive('https://drive.google.com/file/d/1GkgKDPjtnv-WXd8k0Jc1y6su20RFnZy6/view?usp=sharing)),
binSaed commented 3 years ago

@sumitzartek let me know if this fixed ur issue

zizy97 commented 3 years ago

I have the same issue. your solution save my time thanks friend. I waste lot of my time for it. Your solution is the best.thanks again

ameenbadri7 commented 1 year ago

your solution saves me allot of time. I also waste a lot of my time on it. Your answer is the best.

Thank you