Open zhushuihua opened 2 months ago
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?
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.
@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();
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
```dart 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(), ); })), ); } FutureScreenshots or Video
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