Skip to content

[syncfusion_flutter_pdfviewer] Error opening a PDF document - Invalid cross reference table #2293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
saurabhDetharia opened this issue Feb 26, 2025 · 5 comments
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.

Comments

@saurabhDetharia
Copy link

saurabhDetharia commented Feb 26, 2025

Bug description

While loading some PDF documents in Flutter using SfPdfViewer.file returns an error. I have attached some PDFs for the reference.
computer_networks.pdf
sample.pdf

I also tried to load using the same file from the network source and it is having the same issue. Here is the source URL for the pdf I have used.

I have also referred here forum, but could not find the way to implement the below mentioned snippet (as suggested in the forum) in the SfPdfViewer. Is there any way to either resolve the exception or load such PDF files?

// Open an existing corrupted document from disk.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"true);

Steps to reproduce

  1. Create a new flutter web application
    flutter create syncfusion_pdfviewer_poc
  2. Add syncfusion_flutter_pdfviewer package
    flutter pub add syncfusion_flutter_pdfviewer
  3. Add SfPdfViewer widget to load the PDF.
  4. Run the application.

Code sample

Code sample

main.dart

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: SfPdfViewer.network(
        'https://csc-knu.github.io/sys-prog/books/Andrew%20S.%20Tanenbaum%20-%20Computer%20Networks.pdf',
        onDocumentLoadFailed: (error) {
          debugPrint(error.error);
          debugPrint(error.description);
        },
      ),
    );
  }
}

pubspec.yaml

name: syncfusion_pdfviewer_poc
description: "A new Flutter project."

publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: ^3.7.0

dependencies:
  flutter:
    sdk: flutter
    
  cupertino_icons: ^1.0.8
  syncfusion_flutter_pdfviewer: ^28.2.7

dev_dependencies:
  flutter_test:
    sdk: flutter
   
  flutter_lints: ^5.0.0

flutter:  
  uses-material-design: true

Screenshots or Video

Screenshots / Video demonstration
PDF.Loading.Issue.mp4

Stack Traces

Stack Traces
Invalid argument (Invalid cross reference table.): null
#0      CrossTable._initialize (package:syncfusion_flutter_pdf/src/pdf/implementation/io/cross_table.dart:206:7)
#1      new CrossTable (package:syncfusion_flutter_pdf/src/pdf/implementation/io/cross_table.dart:27:5)
#2      PdfCrossTable._initializeCrossTable (package:syncfusion_flutter_pdf/src/pdf/implementation/io/pdf_cross_table.dart:192:18)
#3      new PdfCrossTable (package:syncfusion_flutter_pdf/src/pdf/implementation/io/pdf_cross_table.dart:41:9)
#4      PdfDocument._initialize (package:syncfusion_flutter_pdf/src/pdf/implementation/pdf_document/pdf_document.dart:857:28)
#5      new PdfDocument (package:syncfusion_flutter_pdf/src/pdf/implementation/pdf_document/pdf_document.dart:91:5)
#6      SfPdfViewerState._getPdfFile (package:syncfusion_flutter_pdfviewer/src/pdfviewer.dart:3008:14)
#7      SfPdfViewerState._loadPdfDocument (package:syncfusion_flutter_pdfviewer/src/pdfviewer.dart:2091:56)
<asynchronous suspension>

On which target platforms have you observed this bug?

Android, iOS

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.29.0, on macOS 14.5 23F79 darwin-arm64, locale en-IN) [1,335ms]
    • Flutter version 3.29.0 on channel stable at /Users/saurabh.d/Downloads/flutter 2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 35c388afb5 (2 weeks ago), 2025-02-10 12:48:41 -0800
    • Engine revision f73bfc4522
    • Dart version 3.7.0
    • DevTools version 2.42.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3) [5.1s]
    • Android SDK at /Users/saurabh.d/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0-rc3
    • ANDROID_HOME = /Users/saurabh.d/Library/Android/sdkexport
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4) [1,702ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [10ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2) [10ms]
    • 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 21.0.3+-79915917-b509.11)

[✓] Connected device (5 available) [12.8s]
    • iPhone 15 Pro (mobile)          • 71BC4438-7013-438F-AAE5-EC174AD6F935 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 133.0.6943.128

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

• No issues found!
@immankumarsync
Copy link
Contributor

Hi @saurabhDetharia, we are able to replicate the reported issue that unable to load specific documents due to invalid argument error. Currently, we are validating this issue, and we will update further details once we found the root cause for this issue.

@VijayakumarMariappan VijayakumarMariappan added pdf viewer PDF viewer component follow-up scheduled Follow-up scheduled labels Mar 17, 2025
@immankumarsync
Copy link
Contributor

Hi @saurabhDetharia,

The fix for the reported issue "Invalid cross reference table issue occurs while loading the specific PDF document" has been included in our latest weekly release v29.1.37.

Package link: syncfusion_flutter_pdf 29.1.37, syncfusion_flutter_pdfviewer 29.1.37

Root Cause : The escape characters are not handled properly while loading the annotation. Therefore, Invalid cross reference table issue occurs while loading the specific PDF document

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

Regards,
Imman Kumar P

@Deepak1799 Deepak1799 added solved Solved the query using existing solutions and removed follow-up scheduled Follow-up scheduled labels Apr 14, 2025
@danieletulone
Copy link

danieletulone commented Apr 21, 2025

I have some PDF files that are valid — I can open them using Chrome or any other PDF reader without any issues.

So, I'm investigating running the pdfinfo command from the CLI on these files, I get the following output:

Syntax Error: Couldn't read xref table  
Syntax Warning: PDF file is damaged - attempting to reconstruct xref table...

Could this error be related to this issue?

Current version: 29.1.38 (also tested on 29.1.37) (testing on web platform)

@VijayakumarMariappan VijayakumarMariappan added open Open and removed solved Solved the query using existing solutions labels Apr 22, 2025
@immankumarsync
Copy link
Contributor

Hi @danieletulone,
We suspect that the documents in which you observed the issue may have a different internal structure, which could be the underlying cause. We kindly request you to share the PDF documents where the issue was identified, as this will help us in determining the exact cause and assist you.

If you feel that the documents cannot be shared publicly, you may create a ticket in our support portal to share the requested files securely.

@Deepak1799 Deepak1799 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Apr 22, 2025
@danieletulone
Copy link

Hi @immankumarsync,
I'm sorry, but I’m unable to share those PDFs as they contain sensitive data, and sharing them could potentially conflict with European GDPR regulations. However, I’m currently trying to find some other PDFs that don’t work, which I can safely share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

5 participants