Articles in this section
Category / Section

How to load Flutter SfPdfViewer from memory or bytes?

1 min read

This article explains how to load a PDF document from memory or bytes in Syncfusion® Flutter PDF Viewer.

 

The Syncfusion® Flutter PDF Viewer widget provides the support to load a PDF document from Asset, Network, File, and Memory. The SfPdfViewer.memory is used to load a PDF document from memory or bytes and the below code explains the same. The getPdfBytes( ) method is used to convert the network PDF document as bytes and then load the bytes by using the SfPdfViewer.memory, which creates a widget that displays a PDF document obtained from the Uint8List.

 

Uint8List? _documentBytes;
@override
void initState() {
  getPdfBytes();
  super.initState();
}
 
///Get the PDF document as bytes
void getPdfBytes() async {
  _documentBytes = await http.readBytes(Uri.parse(
      'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf'));
  setState(() {});
}
 
@override
Widget build(BuildContext context) {
  Widget child = const Center(child: CircularProgressIndicator());
  if (_documentBytes != null) {
    child = SfPdfViewer.memory(
      _documentBytes!,
    );
  }
  return Scaffold(
    appBar: AppBar(title: const Text('Syncfusion Flutter PDF Viewer')),
    body: child,
  );
}
 

 

loading PDF from bytes-SfPdfViewer-Flutter.

 

A complete working sample can be downloaded from here.

Take a moment to peruse the documentation for loading PDF documents. You find other options like Asset, File, and Network to load the PDF document.


Conclusion

I hope you enjoyed learning about how to load Flutter SfPdfViewer from memory or bytes.

You can refer to our Flutter PDF Viewer page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied