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

插件详情v3.0.1

pdf_image_renderer

一个使用操作系统原生渲染器实现 PDF 快速简单渲染的包。

AndroidiOS
近 30 天下载
5290
喜欢数
36
Pub 分数
150

安装插件

flutter pub add pdf_image_renderer

插件介绍

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

pdf_image_renderer 包通过利用 Android 和 iOS 的原生 PDF 渲染功能,实现了快速且简单的 PDF 文档渲染。它提供了一种轻量级、高效的解决方案,可将 PDF 页面转换为图像,而无需依赖纯 Dart 实现。这种做法确保了高性能和准确的视觉输出,与原生操作系统行为高度一致。适用于需要快速预览或缩略图的 PDF 应用程序,简化了集成过程,设置简单。该包由 cloudacy.com 维护,兼容两大主流移动平台。

适合场景

  • 生成PDF缩略图
  • 在应用程序中渲染PDF页面
  • 创建文档的图像预览
  • 显示PDF内容而无需完整查看器
  • 在 Flutter 中集成原生 PDF 渲染

主要特点

  • 使用原生操作系统PDF渲染器
  • 高性能和高精度
  • 所需设置最少
  • 跨平台支持(Android、iOS)
  • 轻便高效

适合对象

  • 需要PDF预览的移动应用
  • 基于图像的文档处理
  • 性能敏感的渲染应用
  • 寻求原生渲染保真度的开发者
  • 避免使用大型PDF库的项目

使用建议

  • 仅限 Android 和 iOS
  • 不支持网页或桌面端
  • 依赖于平台特定的PDF渲染
  • 可能因设备操作系统版本略有不同
  • 不支持交互式PDF功能

原始 README

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

pdf_image_renderer

pub package

Renders PDFs to bitmaps using native renderers.

Usage

See the example folder for a fully working flutter example.

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Uint8List image;

  void renderPdfImage() async {
    // Get a path from a pdf file (we are using the file_picker package (https://pub.dev/packages/file_picker))
    String path = await FilePicker.getFilePath(type: FileType.custom, allowedExtensions: ['pdf']);

    // Initialize the renderer
    final pdf = PdfImageRenderer(path: path);

    // open the pdf document
    await pdf.open(
      // password: 'password', // optional (iOS and Android 15.0+ support - ignored otherwise)
    )

    // open a page from the pdf document using the page index
    await pdf.openPage(pageIndex: 0);

    // get the render size after the page is loaded
    final size = await pdf.getPageSize(pageIndex: 0);

    // get the actual image of the page
    final img = await pdf.renderPage(
          pageIndex: pageIndex,
          x: 0,
          y: 0,
          width: size.width, // you can pass a custom size here to crop the image
          height: size.height, // you can pass a custom size here to crop the image
          scale: 1, // increase the scale for better quality (e.g. for zooming)
          background: Colors.white,
        );

    // close the page again
    await pdf.closePage(pageIndex: 0);

    // close the PDF after rendering the page
    pdf.close();

    // use setState to update the renderer
    setState(() {
      image = img;
    });
  }

  @override
  void initState() {
    super.initState();
  }


  // you can use this image later in your build function
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text('pdf_image_renderer'),
          ),
          body: Center(
            child: image != null ? Image(image: MemoryImage(image)) : Text("Loading..."),
          )
        )
    );
  }
}

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.1.8

源码仓库

使用此插件的项目

暂无相关数据。