搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案