We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Bugs with syncfusion_flutter_pdf package pdf loader

Hello,

I have encountered two bugs using the Syncfusion Flutter PDF package. 

  1. For some PDF files will not be loaded, because of an error in the code for getting the font name
  2. For some PDF files, the font size is not read correctly. The size of a lot of the text in the file is 1.0, while the actual size varies but is never 1.0

This is the link of the PDF file: https://drive.google.com/file/d/1Ki7i6JdCrzc4XJbbOlv94mGIkvRqRmU3/view?usp=share_link
T
his PDF has both of the issues. When I encountered the first issue I removed the code for getting the font name, by returning an empty string at the start of the getFontName() method.


My code is:

void loadDocument() async {
  PdfDocument document = PdfDocument(
      inputBytes: await readDocumentData('biological-psychology_compress.pdf'));
  PdfTextExtractor extractor = PdfTextExtractor(document);
  int pageCount = document.pages.count;
  for (int pageNumber = 0; pageNumber < pageCount; pageNumber++) {
    List<TextLine> textLines =
        extractor.extractTextLines(startPageIndex: pageNumber);
    for (int i = 0; i < textLines.length; i++) {
      var line = textLines[i];
    }
  }
}


The error is:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'PdfReferenceHolder' is not a subtype of type 'PdfName?' in type

cast

#0 FontStructure.getFontName (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/font_structure.dart:1130:60)

#1 FontStructure.fontName (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/font_structure.dart:234:41)#2 PdfPageResources.isSameFont.<anonymous closure>.<anonymous closure> (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/page_resource_loader.dart:228:30)

#3 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)

#4 PdfPageResources.isSameFont.<anonymous closure> (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/page_resource_loader.dart:227:22)

#5 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)

#6 PdfPageResources.isSameFont (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/page_resource_loader.dart:226:20)

#7 ImageRenderer._renderTextElementWithLeading (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart:618:42)

#8 ImageRenderer.renderAsImage (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart:373:17)

#9 PdfTextExtractor._getTextLine (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart:317:14)

#10 PdfTextExtractor._extractTextLines (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart:207:14)

#11 PdfTextExtractor.extractTextLines (package:syncfusion_flutter_pdf/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart:126:12)

#12 loadDocument (package:summary_ai/load_document.dart:45:19)

<asynchronous suspension>


So the code that generates the error is:

  /// Extracts the font name associated with the string.
  String? getFontName() {
    String? fontName = '';
    isSystemFontExist = false;
    if (fontDictionary.containsKey(PdfDictionaryProperties.baseFont)) {
      PdfName? baseFont =
          fontDictionary[PdfDictionaryProperties.baseFont] as PdfName?;
      baseFont ??= (fontDictionary[PdfDictionaryProperties.baseFont]!
              as PdfReferenceHolder)
          .object as PdfName?;
      String font = baseFont!.name!;
/// More code
    }
    return fontName;
  }

2 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team April 10, 2023 10:07 AM UTC

We confirmed the issue ”Unhandled exception while extracting text from the PDF document” as a defect in our product and defect and we will include the fix in our upcoming weekly NuGet release, which will be available on April 18th, 2023.

Please use the below feedback link to track the status of the reported bug. https://www.syncfusion.com/feedback/42760/unhandled-exception-while-extracting-text-from-the-pdf-document

Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.




IJ Irfana Jaffer Sadhik Syncfusion Team April 19, 2023 06:59 AM UTC

The fix for the reported issue ”Unhandled exception while extracting text from the PDF document” " has been included in our weekly release v21.1.41.


Kindly use the following link to refer our latest package,           

https://pub.dev/packages/syncfusion_flutter_pdf/versions/21.1.41



Loader.
Live Chat Icon For mobile
Up arrow icon