espresso3389 / pdfrx

pdfrx is yet another PDF viewer implementation that built on the top of PDFium. The plugin currently supports Android, iOS, Windows, macOS, Linux, and Web.
MIT License
117 stars 55 forks source link

errore while loading network #183

Closed dineshnaikb closed 5 months ago

dineshnaikb commented 5 months ago
[log] PdfException: Failed to download PDF file: 416 Requested Range Not Satisfiable
[log] #0      _downloadBlock (package:pdfrx/src/pdf_file_cache.dart:491:5)
      <asynchronous suspension>
      #1      pdfDocumentFromUri (package:pdfrx/src/pdf_file_cache.dart:377:24)
      <asynchronous suspension>
      #2      PdfDocumentListenable.load.<anonymous closure> (package:pdfrx/src/pdf_document_ref.dart:396:22)
      <asynchronous suspension>
      #3      objectSynchronized.<anonymous closure> (package:synchronized/src/extension_impl.dart:37:18)
      <asynchronous suspension>
      #4      BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
      <asynchronous suspension>
      #5      objectSynchronized (package:synchronized/src/extension_impl.dart:34:12)
      <asynchronous suspension>
      #6      PdfDocumentListenable.load (package:pdfrx/src/pdf_document_ref.dart:390:12)
      <asynchronous suspension>

code


import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:pdfrx/pdfrx.dart';

void main() {
  runApp(const MainPage());
}

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  PdfViewerController controller = PdfViewerController();

  bool search = false;

  TextEditingController searchTextFeild = TextEditingController();
  @override
  void initState() {
    super.initState();
    // controller.
  }

  @override
  void dispose() {
    super.dispose();
    searchTextFeild.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: search
            ? AppBar(
                title: TextField(
                  controller: searchTextFeild,
                  decoration: InputDecoration(
                      hintText: "seach here",
                      suffix: IconButton(
                          onPressed: () {
                            // controller.
                          },
                          icon: const Icon(Icons.search))),
                ),
              )
            : AppBar(
                leading: IconButton(
                  icon: const Icon(Icons.menu),
                  onPressed: () {
                    // showLeftPane.value = !showLeftPane.value;
                  },
                ),
                title: const Text('Pdfrx example'),
                actions: [
                  IconButton(onPressed: () {}, icon: const Icon(Icons.bookmark)),
                  IconButton(
                      onPressed: () {
                        search = true;
                      },
                      icon: const Icon(Icons.search)),
                ],
              ),

        body: PdfViewer.uri(
          Uri.parse('https://bugs.python.org/file47781/Tutorial_EDIT.pdf'),
          controller: controller,
          params: PdfViewerParams(
              enableKeyboardNavigation: true,
              // forceReload: true,
              // linkWidgetBuilder: (context, link, size) {
              // return GestureDetector(
              //   child: Container(width: size.width, height: size.height, color: Colors.transparent),
              //   onTap: () {
              //     log(link.toString());
              //   },
              // );
              // },
              enableTextSelection: true,
              errorBannerBuilder: (context, error, stacktrace, ref) {
                log(error.toString());
                log(stacktrace.toString());
                return Container();
              }),
        ),

        // PdfViewer.uri(
        //   Uri.parse('https://bugs.python.org/file47781/Tutorial_EDIT.pdf'),
        //   // passwordProvider: () => 'test',
        // ),
      ),
    );
  }
}```
espresso3389 commented 5 months ago

At least, with 1.0.70, I can correctly show the PDF on Android/Windows. Could you please show me your flutter doctor -v?

dineshnaikb commented 5 months ago

flutter doctor -v [✓] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.22631.3737], locale en-IN) • Flutter version 3.22.2 on channel stable at D:\software\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 761747bfc5 (2 weeks ago), 2024-06-05 22:15:13 +0200 • Engine revision edd8546116 • Dart version 3.4.3 • DevTools version 2.34.3

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\naik9\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.10+0--11609105) • All Android licenses accepted.

[✓] Android Studio (version 2024.1) • Android Studio at C:\Program Files\Android\Android Studio1 • 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.10+0--11609105)

[✓] VS Code (version 1.90.2) • VS Code at C:\Users\naik9\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.91.20240529

[✓] Connected device (2 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.3737] • Edge (web) • edge • web-javascript • Microsoft Edge 125.0.2535.79

[✓] Network resources • All expected network resources are available.

dineshnaikb commented 5 months ago

Thanks for providing a new package, it is search a valuable package to use for PDF, as of now any track of like this with many feathers i have sorted this issue it has been done. The reason of the like has some exp time so it's not loading file and get 416 error of network. I have just replaced the link with another it Woking. But I would like to check the give link valued for PDF fetch

espresso3389 commented 5 months ago

I've identified the cause of the issue. It does not occur on the first time user opens the PDF file. When the user re-visit the same PDF file, the site let the PDF viewer to re-download the content and then the client mis-behaves due to an internal logic error.

espresso3389 commented 5 months ago

1.0.71 contains the fix.