syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.44k stars 672 forks source link

Widget takes forever to load when password encrypted file is opened on Desktop #1808

Open hkpanchani opened 1 month ago

hkpanchani commented 1 month ago

Bug description

It opens the password less files very smoothly, but takes forever to open encrypted files on desktop (both windows and mac)

Password less file => Without Password.pdf

With password file => Encrypted File.pdf Password for file is 2yF72KCdTvKNBiwcNj

Steps to reproduce

Simply load a pdf file with password and without password.

Code sample

Code sample ```dart Widget build(BuildContext context) { return Scaffold( appBar: AppBar( centerTitle: true, title: Text('Pdf Viewer',style: styleSegoeBold(18, Colors.black),), leading: IconButton( icon: const Icon(Iconsax.arrow_left), onPressed: () { Navigator.pop(context); }, ), ), body: SfPdfViewer.file( widget.pdfFile, key: _pdfViewerKey, enableTextSelection: false, interactionMode: PdfInteractionMode.pan, scrollDirection: PdfScrollDirection.vertical, canShowPasswordDialog: false, password: widget.password, pageLayoutMode: PdfPageLayoutMode.single, ), ); } } ```

Screenshots or Video

Screenshots / Video demonstration https://github.com/syncfusion/flutter-widgets/assets/35301566/18b7e535-a5e8-4733-b14a-967969a4eac9

Stack Traces

Stack Traces ```dart None. No error displayed ```

On which target platforms have you observed this bug?

Windows, macOS

Flutter Doctor output

Doctor output ```console macos@macos ~ % flutter doctor -v [!] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-US) • Flutter version 3.19.5 on channel stable at /opt/homebrew/Caskroom/flutter/3.19.5/flutter ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.3.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /opt/homebrew/Caskroom/flutter/3.19.5/flutter. Consider adding /opt/homebrew/Caskroom/flutter/3.19.5/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (3 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/macos/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a ✗ Unable to get list of installed Simulator runtimes. • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] VS Code (version 1.88.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension can be installed from: 🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.124 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 2 categories. ```
hkpanchani commented 1 month ago

Also very small files less than 1MB opens well with password also.

dbbusa commented 1 month ago

When prompted for a password upon opening a PDF file, there is a delay in saving the password, followed by a return to the loading stage. Subsequently, the time required for the file to open is significantly prolonged, with the duration contingent upon the size of the PDF file.

img1

img2

hkpanchani commented 1 month ago

@VijayakumarMariappan Which pdf viewer engine does this library use to view pdf in desktop?

The Only Issue is the slowness is directly proportional to type of encryption algorithm used, It opens well with RC encryption, But if we use AES encryption it takes a lot of time to view the pdf file.

Regular Chrome or any other browser/ pdf viewer can open AES encrypted files in milliseconds.

immankumarsync commented 1 month ago

Hi @hkpanchani,

We use the following libraries to render the PDF.

Windows - pdfium macOS, iOS - CGPDFDocument Andoird - PdfRenderer Web - pdf.js

We create PDF document instance using these libraries to retrieve the image of the PDF pages.

We suspect that in the provided document, all the content of the PDF document is also encrypted. Due to this encryption, the whole content of the document needs to be decrypted, hence the PDF document instance creation takes longer than the normal PDF document.

hkpanchani commented 1 month ago

It might be possible that content might be encrypted, but I also tried using syncfusion_flutter_pdf to encrypt document, it still takes the same time.

Would you like me try something and send the output? @immankumarsync Is it possible to get help here?

immankumarsync commented 1 month ago

Hi @hkpanchani, In SfPdfViewer widget, while loading an encrypted document, we decrypt the PDF document with the provided password, and then we pass this document to the platform PDF renderers. We found that the delay occurs in decrypting the document. Currently, we are analyzing this case, and then we will update further details.

mratanpara commented 3 weeks ago

Hello @hkpanchani , have you found a solution?

I'm encountering a similar problem with the SfPdfViewer widget in this plugin. It works smoothly with passwordless files but takes an eternity to open encrypted files on both Windows and Mac desktop platforms.

hkpanchani commented 3 weeks ago

Not yet, Nothing. @immankumarsync and team are checking on this one why it is taking time to decrypt the file.

immankumarsync commented 3 weeks ago

@hkpanchani, In Syncfusion Flutter PDF Viewer, we utilize Syncfusion PDF Library to decrypt encrypted PDF documents, save the decrypted content, and then load these decrypted bytes into the native PDF renderers.

The provided encrypted PDF document (File: Encrypted_File.pdf, Size: 11065KB) has all its contents encrypted. When we remove the encryption from this document, we decrypt its contents and then compress them again. Given that the size of the PDF document is 11 MB, based on our analysis, this process took approximately 21 seconds, and is expected.