Skip to content
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

Updating PDF page #1657

Open
2 tasks done
LuisHer27 opened this issue May 2, 2024 · 0 comments
Open
2 tasks done

Updating PDF page #1657

LuisHer27 opened this issue May 2, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@LuisHer27
Copy link

Describe the bug

  • I'm trying to add a signature in the last page of the pdf and I want put the signature at the bottom of the page. But it seems like I'm not able to achieve it. The text looks flipped and I can't manipulate the blue container location.

To Reproduce
Code snippet to reproduce the behavior:

Future<File> getFile() async {
  final data = await rootBundle.load('assets/participant_agreement.pdf');
  final bytes = data.buffer.asUint8List();
  final dir = await getApplicationDocumentsDirectory();
  final file = File('${dir.path}/form.pdf');

  final assetFile = await file.writeAsBytes(bytes);

  return assetFile;
}

class PdfEditorService {
  const PdfEditorService._();

  static Future<File> addSignatureToPDF(Uint8List signature) async {
    try {
      final font = await PdfGoogleFonts.nunitoExtraLight();

      final file = await getFile();
      final form = file.readAsBytesSync();

      final image = MemoryImage(signature);

      final document = PdfDocumentParser(
        form,
      );

      final lastPage = document.pages.length - 1;

      final themePage = PageTheme(
        pageFormat: PdfPageFormat.a4,
        buildBackground: (context) {
          return Container(color: PdfColors.blue);
        },
      );

      final pdf = Document.load(document)
        ..editPage(
          lastPage,
          Page(
            pageTheme: themePage,
            build: (context) {
              return Column(
                children: [
                  Text(
                    'Participant Agreement Form',
                    style: TextStyle(
                      font: font,
                      fontSize: 32,
                    ),
                  ),
                  SizedBox(height: 12),
                  Text(
                    'Name: Anakin Skywalker',
                    style: TextStyle(
                      font: font,
                      fontSize: 32,
                    ),
                  ),
                  Positioned(
                    top: 0,
                    left: 0,
                    child: Column(
                      children: [
                        Text(
                          'Signature',
                          style: TextStyle(
                            font: font,
                            fontSize: 32,
                          ),
                        ),
                        SizedBox(height: 20),
                        Image(image),
                        SizedBox(height: 8),
                        Container(
                          height: 1,
                          width: 200,
                          decoration: BoxDecoration(
                            border: Border.all(),
                          ),
                        ),
                        SizedBox(height: 10),
                        Text(
                          'Date: 2021-09-01',
                          style: TextStyle(
                            font: font,
                            fontSize: 32,
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              );
            },
          ),
        );

      final dir = await getApplicationDocumentsDirectory();
      final signedForm = File('${dir.path}/form.pdf');
      return await signedForm.writeAsBytes(await pdf.save());
    } catch (e) {
      log(e.toString());
      throw Exception('Error adding signature to PDF');
    }
  }
}

Expected
expected_behavior.pdf
behavior

Screenshots
Screenshot 2024-05-02 at 10 45 43 a m

Flutter Doctor

[✓] Flutter (Channel stable, 3.19.6, on macOS 14.2.1 23C71 darwin-arm64, locale en-MX)
    • Flutter version 3.19.6 on channel stable at /Users/huicho/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (2 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huicho/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.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    ✗ 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.2)
    • 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.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.86.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.84.0

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile) • emulator-5556             • android-arm64  • Android 14 (API 34) (emulator)
    • Iphone Huicho (mobile)      • 00008120-00086C122120C01E • ios            • iOS 17.4.1 21E236
    • Iphone Luis (mobile)        • 00008101-001C48940C29001E • ios            • iOS 17.4.1 21E236
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 124.0.6367.94
    ! Device emulator-5554 is offline.

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

Desktop (please complete the following information):

  • iOS
  • Android

Smartphone (please complete the following information):

  • Device: [iPhone 14]
  • OS: [Pixel 8]
  • Version [e.g. 22]

Additional context

@LuisHer27 LuisHer27 added bug Something isn't working needs triage labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant