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

runtime error #2057

Open
zhushuihua opened this issue Sep 5, 2024 · 3 comments
Open

runtime error #2057

zhushuihua opened this issue Sep 5, 2024 · 3 comments
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.

Comments

@zhushuihua
Copy link

Bug description

The createTemplate caused program to crash.

Steps to reproduce

Ran the program at iOS simulator and as Mac OS app all caused the same crash.

Code sample

Code sample
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdf/pdf.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 const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
          child: FutureBuilder(
              future: _makeData(),
              builder: (ctx, snapshot) {
                if (snapshot.hasData) {
                  return SfPdfViewer.memory(snapshot.data!);
                }
                return const Center(
                  child: CircularProgressIndicator(),
                );
              })),
    );
  }

  Future<Uint8List> _makeData() async {
    final doc1 = _makePdf();
    doc1.pages[0].createTemplate();
    return Uint8List.fromList(await doc1.save());
  }

  PdfDocument _makePdf() {
    final PdfDocument document = PdfDocument();
    document.pages.add().graphics.drawString(
        'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
        brush: PdfSolidBrush(PdfColor(0, 0, 0)),
        bounds: const Rect.fromLTWH(0, 0, 150, 20));
    // document.dispose();
    return document;
  }
}

Screenshots or Video

Screenshot 2024-09-05 at 5 17 02 PM

Stack Traces

It seems the PdfPage is not the PdfPage is meant to be.

Exception has occurred.
_TypeError (Null check operator used on a null value)

On which target platforms have you observed this bug?

iOS, macOS

Flutter Doctor output

[✓] Flutter (Channel stable, 3.24.1, on macOS 14.6.1 23G93 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.4)
[✓] VS Code (version 1.92.2)
[✓] Connected device (5 available)
[✓] Network resources

@LavanyaGowtham2021 LavanyaGowtham2021 added pdf viewer PDF viewer component open Open labels Sep 5, 2024
@immankumarsync
Copy link
Contributor

Hi @zhushuihua, we are able to replicate the reported issue. However, could you please share the use of using the createTemplate method, as we can see that the PdfTemplate returned from the method is not utilized elsewhere?

@zhushuihua
Copy link
Author

I need to use it to combine 2 PdfDocument as 1. I have found a bypass to this issue. However this behavior seems to be very strange to me.

@immankumarsync
Copy link
Contributor

@zhushuihua,
The createTemplate method is designed to work exclusively with loaded pages. Creating a page template for a new page is not supported.

Kindly use the following link for reference,
Creating templates from existing PDF document

You can use the below code to get the template of the page,

final PdfDocument document = PdfDocument();
document.pages.add().graphics.drawString(
    'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)),
    bounds: const Rect.fromLTWH(0, 0, 150, 20));

final List<int> savedBytes = await document.save();
document.dispose();

final PdfDocument loadedDocument = PdfDocument(
  inputBytes: Uint8List.fromList(savedBytes),
);
final PdfTemplate template = loadedDocument.pages[0].createTemplate();

@Deepak1799 Deepak1799 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Sep 12, 2024
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

4 participants