首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >在颤振中显示iOS的PDF内联文件

在颤振中显示iOS的PDF内联文件
EN

Stack Overflow用户
提问于 2018-08-14 06:30:37
回答 5查看 12.2K关注 0票数 10

我正在为iOS (在这个阶段)专门开发一个应用程序,我需要添加PDF文件到它。问题是颤振没有显示PDF文件的原生方式(据我所研究)。

从这个踏面看来,使用插件向iOS设备添加PDF支持似乎不太困难。然而,我仍然对如何将它集成到我的颤振应用程序中感到困惑。

任何帮助都将不胜感激!

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2018-09-30 22:00:39

当我实现PDF查看器的功能时,没有PDF插件。

然而,有趣的是,工作中的一个朋友发现,已经有一个PDF查看器实现了颤振这里,我们最终使用了它。

注:在撰写问题时,16.08还没有任何插件可用。上述是在30.08上创建的。

票数 3
EN

Stack Overflow用户

发布于 2020-06-28 00:04:14

如果您正在寻找快速和简单的方式显示PDF,这可能是一个。

颤动

从网络加载PDF:

代码语言:javascript
代码运行次数:0
运行
复制
PDF.network(
        'https://raw.githubusercontent.com/FlutterInThai/Dart-for-Flutter-Sheet-cheet/master/Dart-for-Flutter-Cheat-Sheet.pdf',
        height: 500,
        width: 300,
        )

从档案中载入PDF:

代码语言:javascript
代码运行次数:0
运行
复制
File fileName;  
PDF.file(
    fileName,
    height: 200,
    width: 100,
)

从资产加载PDF:

代码语言:javascript
代码运行次数:0
运行
复制
PDF.assets(
    "assets/pdf/demo.pdf",
    height: 200,
    width: 100,
)

票数 1
EN

Stack Overflow用户

发布于 2020-02-24 17:48:59

在pubspec.yaml中添加依赖项

pubspec.yaml

代码语言:javascript
代码运行次数:0
运行
复制
dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  pdf_viewer_plugin: ^1.0.0+2
  path_provider: ^1.6.1
  http: ^0.12.0+4

main.dart

代码语言:javascript
代码运行次数:0
运行
复制
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:pdf_viewer_plugin/pdf_viewer_plugin.dart';
import 'package:path_provider/path_provider.dart';
import 'package:http/http.dart' as http;

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
  String path;
  @override
  initState() {
    super.initState();
  }
  Future<String> get _localPath async {
    final directory = await getApplicationDocumentsDirectory();

    return directory.path;
  }

  Future<File> get _localFile async {
    final path = await _localPath;
    return File('$path/teste.pdf');
  }

  Future<File> writeCounter(Uint8List stream) async {
    final file = await _localFile;
    // Write the file
    return file.writeAsBytes(stream);
  }

  Future<Uint8List> fetchPost() async {
    final response = await http.get(
        'https://expoforest.com.br/wp-content/uploads/2017/05/exemplo.pdf');
    final responseJson = response.bodyBytes;

    return responseJson;
  }

  loadPdf() async {
    writeCounter(await fetchPost());
    path = (await _localFile).path;

    if (!mounted) return;

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              if (path != null)
                Container(
                  height: 300.0,
                  child: PdfViewer(
                    filePath: path,
                  ),
                )
              else
                Text("Pdf is not Loaded"),
              RaisedButton(
                child: Text("Load pdf"),
                onPressed: loadPdf,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51835013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档