Skip to content

Incorrect text selection spacing and screen turns white on highlight in specific PDFs #2350

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

Closed
minhto2811 opened this issue May 13, 2025 · 2 comments
Labels
open Open pdf viewer PDF viewer component

Comments

@minhto2811
Copy link

Bug description

When opening certain PDF files with syncfusion_flutter_pdfviewer, the following issues occur:

Text selection is misaligned: selected text appears with irregular spacing or offset between words/lines.

When trying to highlight the selected area, the screen turns white, making the content invisible.

This behavior only occurs with specific PDF files, especially ones with custom fonts or complex internal structures.

example.pdf

Steps to reproduce

1.Open the application that uses the syncfusion_flutter_pdfviewer package.

2.Load a PDF file with complex layouts, custom fonts, or scanned text (the issue appears specifically with certain PDFs).

3.Select text from the PDF.

4.Notice that the text selection is misaligned or spaced incorrectly.

5.Highlight the selected text.

6.The screen turns white and the content becomes invisible.

Code sample

Code sample
SfPdfViewer.memory(
      bytes,
      key: key,
      initialPageNumber: initialPageNumber,
      onPageChanged: onPageChanged,
      onHyperlinkClicked: onHyperlinkClicked,
      controller: controller,
      canShowPageLoadingIndicator: false,
      canShowTextSelectionMenu: false,
    );


  void _onEdit(OnEditEvent event, Emitter<ViewState> emit) {
    final List<PdfTextLine> selectedLines =
        _pdfViewerKey.currentState!.getSelectedTextLines();
    if (selectedLines.isNotEmpty) {
      Annotation? annotation;
      if (event.mode == PdfAnnotationMode.highlight) {
        annotation = HighlightAnnotation(textBoundsCollection: selectedLines);
      } else if (event.mode == PdfAnnotationMode.underline) {
        annotation = UnderlineAnnotation(textBoundsCollection: selectedLines);
      } else if (event.mode == PdfAnnotationMode.strikethrough) {
        annotation = StrikethroughAnnotation(
          textBoundsCollection: selectedLines,
        );
      } else if (event.mode == PdfAnnotationMode.squiggly) {
        annotation = SquigglyAnnotation(textBoundsCollection: selectedLines);
      }
      _controller.clearSelection();
      if (annotation == null) return;
      _controller.addAnnotation(annotation);
      emit(const OnChangeState(hasUndo: true, hasRedo: false));
      _anotationsUndo.add(annotation);
    }
  }

</details>


### Screenshots or Video

https://github.com/user-attachments/assets/599eb7b2-458c-442e-995d-bb7d33b8324f

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Stack Traces

<details open><summary>Stack Traces</summary>

```dart
[Add the Stack Traces here]

On which target platforms have you observed this bug?

iOS, Android

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version 10.0.26100.3775], locale en-US) [306ms]
    • Flutter version 3.29.0 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 35c388afb5 (3 months ago), 2025-02-10 12:48:41 -0800
    • Engine revision f73bfc4522
    • Dart version 3.7.0
    • DevTools version 2.42.2

[√] Windows Version (Windows 11 or higher, 24H2, 2009) [1,918ms]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [5.1s]
    • Android SDK at C:\Users\maxim\AppData\Local\Android\Sdk
    • Platform android-35, build-tools 35.0.1
    • ANDROID_HOME = C:\Users\maxim\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Java\jdk-17\bin\java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
    • All Android licenses accepted.

[√] Chrome - develop for the web [25ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps [24ms]
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2024.3) [22ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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.6+-13355223-b631.42)

[√] VS Code (version 1.99.3) [20ms]
    • VS Code at C:\Users\maxim\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.109.20250401

[√] Connected device (4 available) [287ms]
    • 24117RN76O (mobile) • amonjvtgylzhfqnz • android-arm64  • Android 15 (API 35)
    • Windows (desktop)   • windows          • windows-x64    • Microsoft Windows [Version 10.0.26100.3775]
    • Chrome (web)        • chrome           • web-javascript • Google Chrome 136.0.7103.93
    • Edge (web)          • edge             • web-javascript • Microsoft Edge 136.0.3240.50

[√] Network resources [440ms]
    • All expected network resources are available.
@LavanyaGowtham2021 LavanyaGowtham2021 added pdf viewer PDF viewer component open Open labels May 13, 2025
@immankumarsync
Copy link
Contributor

Hi @minhto2811,

We were unable to replicate the reported issue where the PDF page goes blank when adding highlight annotations. Please find the sample we used to replicate the reported issue and the video recording of the issue replication attempt below

sfpdfviewer_gh2350.zip

Screen Recording.zip

Could you please try using our sample and let us know if the issue can be replicated on your end?

If you are able to reproduce the issue by modifying our sample, kindly share the updated version so that we can replicate the issue on our end and provide you with a prompt solution.

@minhto2811
Copy link
Author

Thank you for your response. I’ll go ahead and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open Open pdf viewer PDF viewer component
Projects
None yet
Development

No branches or pull requests

3 participants