搜尋套件、儲存庫與 APP 分類

套件詳情v0.7.0

flutter_html_to_pdf

從 HTML 程式碼範本產生 PDF 文件的 Flutter 插件

AndroidiOS
近 30 天下載
2150
喜歡數
120
Pub 分數
150

安裝套件

flutter pub add flutter_html_to_pdf

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,可從 HTML 程式碼範本產生 PDF 文件。它允許開發者直接從 HTML 與 CSS 渲染豐富且具樣式的內容,非常適合在 Flutter 應用中建立發票、報表與可列印文件。此插件支援 Android 與 iOS 平台,並能與現有的 HTML 設計無縫整合。它利用原生渲染功能,確保跨裝置的高品質輸出與一致的格式。

適用情境

  • 產生可列印的發票
  • 建立動態報告
  • 將使用者產生的 HTML 內容渲染為 PDF
  • 匯出應用內容以分享
  • 在Flutter應用中構建文件模板

主要特色

  • HTML 和 CSS 支持
  • 跨平台(Android 與 iOS)
  • 高保真PDF渲染
  • 與 Flutter 的簡單整合
  • 支援響應式版面

適合對象

  • 開發報告功能的開發者
  • 需要 PDF 導出功能的應用
  • 使用 HTML 模板的文件專案
  • 與現有網頁內容整合的團隊
  • 需要列印就緒輸出的行動應用程式

使用建議

  • 對高級CSS功能的支援有限
  • 效能可能會因複雜的HTML而有所差異
  • 需要正確的 HTML 結構以獲得最佳效果
  • 不適用於非常大的文件
  • 可能需要平台特定的調整

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_html_to_pdf

pub package

Flutter plugin for generating PDF files from HTML

Usage
var htmlContent =
"""
<!DOCTYPE html>
<html>
<head>
  <style>
  table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
  }
  th, td, p {
    padding: 5px;
    text-align: left;
  }
  </style>
</head>
  <body>
    <h2>PDF Generated with flutter_html_to_pdf plugin</h2>
    <table style="width:100%">
      <caption>Sample HTML Table</caption>
      <tr>
        <th>Month</th>
        <th>Savings</th>
      </tr>
      <tr>
        <td>January</td>
        <td>100</td>
      </tr>
      <tr>
        <td>February</td>
        <td>50</td>
      </tr>
    </table>
    <p>Image loaded from web</p>
    <img src="https://i.imgur.com/wxaJsXF.png" alt="web-img">
  </body>
</html>
""";

var targetPath = "/your/sample/path";
var targetFileName = "example_pdf_file"

var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(
    htmlContent, targetPath, targetFileName);

Code above simply generates PDF file from HTML content. It should work with most of common HTML markers. You don’t need to add .pdf extension to targetFileName because plugin only generates PDF files and extension will be added automatically.

Other Usages

You can also pass File object with HTML content inside as parameter

var file = File("/sample_path/example.html");
var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlFile(
    file, targetPath, targetFileName);

or even just path to this file

var filePath = "/sample_path/example.html";
var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlFilePath(
    filePath, targetPath, targetFileName);
Images

If your want to add local image from device to your HTML you need to pass path to image as src value.

<img src="file:///storage/example/your_sample_image.png" alt="web-img">

or if you want to use the image File object

<img src="${imageFile.path}" alt="web-img">

Many images inside your document can significantly affect the final file size so I suggest to use flutter_image_compress plugin.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。