搜索插件、代码仓与 APP 分类

flutter_cached_pdfview 封面
插件详情v0.4.4

flutter_cached_pdfview

一个用于在 iOS 和 Android 上显示原生 PDF 视图的包,支持从路径、资源或 URL 打开并缓存。

AndroidiOS
近 30 天下载
4.6万
喜欢数
501
Pub 分数
140

安装插件

flutter pub add flutter_cached_pdfview

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可在 iOS 和 Android 上实现原生 PDF 查看功能,支持从本地路径、资源或 URL 加载 PDF。它会自动缓存已加载的 PDF 以提高性能并减少后续访问的加载时间。设计用于无缝集成,设置简单,确保跨平台高效管理资源并流畅渲染 PDF 文档。

适合场景

  • 从本地存储显示PDF
  • 从网络 URL 加载 PDF
  • 渲染嵌入应用资源中的PDF文件
  • 缓存频繁访问的PDF文件
  • 首次下载后的离线PDF查看

主要特点

  • 支持多种PDF源(路径、资源、URL)
  • 自动缓存下载的PDF文件
  • iOS 和 Android 的原生渲染
  • 高效的内存使用
  • 简单的 API 用于集成

适合对象

  • 需要离线访问PDF的应用程序
  • 可下载内容的电子学习平台
  • 文档密集型应用
  • 带有动态PDF内容的移动应用

使用建议

  • 需要互联网访问以获取远程PDF文件
  • 缓存管理可能需要手动处理
  • 大型PDF文件可能会影响性能
  • PDF 查看器 UI 的自定义功能有限
  • 平台特定的渲染差异

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_cached_pdfview

Awesome Flutter

Pub Version GitHub repo size issues-raw license last-commit stars Dart CI


A package to show Native PDF View for iOS and Android, support Open from a different resource like Path, Asset or Url and Cache it.

📖 Read the case study — how this package is built and maintained — and the step-by-step usage guide by the author.

Support = [ Android , IOS and WEB(soon) ];
  • Open Pdf From Path(local file)
  • Open Pdf From Asset
  • Open Pdf From URl and Cache it
  • Display horizontally or vertically
  • Drag and zoom
  • Double tap for zoom
  • Support password protected pdf
  • Jump to a specific page in the pdf

Setup
iOS

Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

iOS (only support> 11.0) you need to add this line in your ios/Podfile

platform :ios, '11.0'

ready-made in the Example

Import it

Now in your Dart code, you can use:

import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';

Options

Name Android iOS Default
defaultPage ✅ ✅ 0
onViewCreated ✅ ✅ null
onRender ✅ ✅ null
onPageChanged ✅ ✅ null
onError ✅ ✅ null
onPageError ✅ ❌ null
onLinkHandle ✅ ✅ null
gestureRecognizers ✅ ✅ null
filePath ✅ ✅
fitPolicy ✅ ❌ FitPolicy.WIDTH
enableSwipe ✅ ✅ true
swipeHorizontal ✅ ✅ false
password ✅ ✅ null
nightMode ✅ ❌ false
autoSpacing ✅ ✅ true
pageFling ✅ ✅ true
pageSnap ✅ ❌ true
preventLinkNavigation ✅ ✅ false
bockgroundColor ✅ ✅ null

Controller Options

Name Description Parameters Return
getPageCount Get total page count - Future<int>
getCurrentPage Get current page - Future<int>
setPage Go to/Set page int page Future<bool>

Example

from Asset
       PDF(
        enableSwipe: true,
        swipeHorizontal: true,
        autoSpacing: false,
        pageFling: false,
        backgroundColor: Colors.grey,
        onError: (error) {
          print(error.toString());
        },
        onPageError: (page, error) {
          print('$page: ${error.toString()}');
        },
        onPageChanged: (int page, int total) {
          print('page change: $page/$total');
        },
      ).fromAsset('assets/pdf/file-example.pdf'),

cached From Url
      PDF(
        swipeHorizontal: true,
      ).cachedFromUrl('https://ontheline.trincoll.edu/images/bookdown/sample-local-pdf.pdf'),

with placeholder until pdfFile download and errorWidget if there are problem
      PDF().cachedFromUrl(
             'https://ontheline.trincoll.edu/images/bookdown/sample-local-pdf.pdf',
             placeholder: (progress) => Center(child: Text('$progress %')),
             errorWidget: (error) => Center(child: Text(error.toString())),
           )

For production usage

If you use proguard, you should include this line [ready-made in the Example].

-keep class com.shockwave.**

Dependencies

Flutter

flutter_pdfview

flutter_cache_manager

Android (only support >= api 20)

AndroidPdfViewer

iOS (only support> 11.0)

PDFKit

Video

IOS

WEB

Developer

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目