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

flutter_pdf: Issue with x-coordinate when drawing on existing pages of existing PDF's #1844

Open joaocardosoit opened 2 weeks ago

joaocardosoit commented 2 weeks ago

Bug description

I'm using syncfusion_flutter_pdf: ^25.1.42

My issue is related to different behaviours of coordinates when drawing on existing pages of existing pdfs. Example when drawing a square at the coordinate position (0,0) in 2 PDFs:

Steps to reproduce

  1. Make sure the PDF file to test is in the assets folder
  2. Run the main function

Code sample

Code sample ```dart import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; import 'package:syncfusion_flutter_pdf/pdf.dart'; Future main() async { final res = await pdfAddRectangle('assets/test_with_margins.pdf'); final path = (await getApplicationDocumentsDirectory()).path; await File("$path/test_with_margins_output.pdf").writeAsBytes(res); } Future> pdfAddRectangle(String filePath) async { final ByteData data = await rootBundle.load(filePath); final document = PdfDocument(inputBytes: data.buffer.asUint8List()); final page = document.pages[0]; debugPrint("File: $filePath"); debugPrint("Page size: ${page.size.width} x ${page.size.height}"); debugPrint("Page client size: ${page.getClientSize().width} x ${page.getClientSize().height}"); page.graphics.drawRectangle( pen: PdfPen( PdfColor(256, 0, 0), width: 2, ), bounds: const Rect.fromLTWH(0, 0, 200, 200), ); var saveDoc = await document.save(); document.dispose(); return saveDoc; } ```

Screenshots or Video

Screenshots / Video demonstration ##### 1st PDF output (ok) ![test_without_margins pdf_page-0001](https://i.postimg.cc/BncwjTSZ/test-without-margins-pdf-page-0001.jpg) ##### 2nd PDF output (issue) ![test_with_margins pdf_page-0001.png](https://i.postimg.cc/KvfTcJLG/test-with-margins-pdf-page-0001.jpg)
Files - 1st pdf - INPUT: [test_without_margins_input.pdf](https://github.com/syncfusion/flutter-widgets/files/15190754/test_without_margins.pdf) - 2nd pdf - INPUT: [test_with_margins_input.pdf](https://github.com/syncfusion/flutter-widgets/files/15190759/test_with_margins.pdf) - 1st pdf - OUTPUT: [test_without_margins_output.pdf](https://github.com/syncfusion/flutter-widgets/files/15190761/test_without_margins_output.pdf) - 2nd pdf - OUTPUT: [test_with_margins_output.pdf](https://github.com/syncfusion/flutter-widgets/files/15190763/test_with_margins_output.pdf)

Stack Traces

Stack Traces ```dart [Add the Stack Traces here] ```

On which target platforms have you observed this bug?

Android, iOS

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.19.2, on macOS 13.6 22G120 darwin-arm64, locale en-PT) • Flutter version 3.19.2 on channel stable at /Users/joaocardoso/src/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7482962148 (9 weeks ago), 2024-02-27 16:51:22 -0500 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/joaocardoso/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.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 15.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C65 ✗ 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.1) • 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.7+0-17.0.7b1000.6-10550314) [✓] VS Code (version 1.85.1) • VS Code at /Users/joaocardoso/Downloads/Visual Studio Code.app/Contents • Flutter extension version 3.88.0 [✓] Connected device (3 available) • iPhone de João (mobile) • 00008101-000828262110001E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 13.6 22G120 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.118 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
jeyalakshmit commented 2 weeks ago

We were unable to reproduce the reported issue, the "test-with_margins_output.pdf" is generated as expected" and share the working samples with output generated from our side. Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdf_demo_sample_17514949949.zip Output: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Output-1989656091.zip

joaocardosoit commented 2 weeks ago

I uploaded the wrong input file to reproduce the reported issue. To do this, you must use this file: test_with_margins.pdf

jeyalakshmit commented 1 week ago

We were able to reproduce the reported issue with the provided details on our end, and currently we are analyzing it. We will provide further details on May 8th, 2024.

jeyalakshmit commented 1 week ago

We have confirmed the issue ”Preservation issue occurs when drawing in the page graphics in specific PDF document” as a defect in our product and fix will be included in our upcoming weekly release, which will be available on May 21, 2024.

Use the below feedback link to track the status of the reported bug.

https://www.syncfusion.com/feedback/56920/preservation-issue-occurs-when-drawing-in-the-page-graphics-in-specific-pdf

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.”