flutter中如何支持pdf的阅读?

码云
2020-11-08 10:25

flutter中可以使用插件pdf_flutter实现pdf的在线阅读,具体代码示例如下:

  • 添加依赖包
dependencies:
  pdf_flutter: ^1.1.3

 

  • 示例代码:
import 'package:pdf_flutter/pdf_flutter.dart';

//从网络读取pdf
PDF.network('https://raw.githubusercontent.com/FlutterInThai/Dart-for-Flutter-Sheet-cheet/master/Dart-for-Flutter-Cheat-Sheet.pdf',
        height: 500,
        width: 300,
        );

//从文件读取pdf
File fileName;  
PDF.file(
    fileName,
    height: 200,
    width: 100,
)

//从assets读取Pdf
PDF.assets(
    "assets/pdf/demo.pdf",
    height: 200,
    width: 100,
)

 

全部评论