Skip to main content

Native print dialog, share sheet and PDF preview for Flet apps — wraps the Flutter printing package

Project description

flet-printing

Native print dialog / share sheet for Flet apps — wraps the Flutter printing package.

Flet has no built-in printing API. Flutter has a mature one. This extension bridges the gap, the same way official extensions like flet-audio wrap audioplayers.

The demand is documented: flet-dev/flet#894 (Jan 2023) asked for exactly this — PDF printing via the printing package — was closed as "completed" without a shipped solution, and the follow-up question "What's the completed solution for this?" (Feb 2024) was never answered. This package is that answer.

日本語補足: Fletには印刷APIがありません(0.85時点・全API確認済み)。 Flutterのprintingパッケージ(ネイティブ印刷ダイアログ・共有シート)を Flet拡張として包んだものです。ワープロ的なアプリの「ファイル→印刷…」を Fletで実装できます。

Usage

import flet as ft
from flet_printing import Printing

def main(page: ft.Page):
    printing = Printing()
    page.services.append(printing)

    async def print_click(e):
        pdf = open("document.pdf", "rb").read()
        sent = await printing.print_pdf(pdf, name="document")
        # sent=True: 印刷された / False: ダイアログでキャンセル

    page.add(ft.FilledButton("印刷…", on_click=print_click))

ft.run(main)

API:

  • await printing.print_pdf(pdf, name="document") — open the platform print dialog (printer selection / copies / duplex / save-as-PDF) for the given PDF bytes. Returns False if the user cancelled.
  • await printing.share_pdf(pdf, filename="document.pdf") — open the platform share sheet (mobile) / save dialog (desktop).

PdfPreview — display a PDF with print/share built in

from flet_printing import PdfPreview

page.add(PdfPreview(src=pdf_bytes, pdf_file_name="document.pdf",
                    expand=True))

Renders the PDF pages (scrollable) with an action bar: print and share buttons work out of the box. Properties: src (bytes or base64), allow_printing, allow_sharing, use_actions, pdf_file_name, on_printed/on_shared events. can_change_page_format / can_change_orientation are off by default (the PDF you pass is already laid out).

There is deliberately no HTML-to-PDF here: printing's convertHtml is deprecated. Generate the PDF yourself (e.g. headless Chrome for exact CJK typesetting) and pass the bytes to print_pdf.

Installation

Like every third-party Flet extension, this works with apps compiled via flet build (the prebuilt flet run client only bundles official extensions).

Add to your app's pyproject.toml:

dependencies = [
  "flet-printing",
  "flet>=0.85.3",
]

then flet build linux (or windows / macos / apk / ipa).

A runnable example lives in examples/flet_printing_example (build verified on Linux: extension registers, app launches, print dialog opens from the button).

Platform support

Follows the printing package: Android / iOS / macOS / Windows / Linux (via CUPS) / web. See the printing package docs for details.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_printing-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flet_printing-0.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file flet_printing-0.2.0.tar.gz.

File metadata

  • Download URL: flet_printing-0.2.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flet_printing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 54bd96700702705fa05dd3004045c9a916c007a94042f957217b1bea07b1ecf4
MD5 9534ca2ef694c97cdcd66f2b26ce3d14
BLAKE2b-256 dc8a18ca756f165c6541bef2f6445620de9ed51940d905c0bd0cb87887c3ca3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for flet_printing-0.2.0.tar.gz:

Publisher: publish.yml on aiseed-dev/flet-printing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flet_printing-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: flet_printing-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flet_printing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d219c1861f979320a2ddeadddc83136e220275403aa5ef10c772984e4cce0b9
MD5 cd87783f4a552a75a375150f3271acc0
BLAKE2b-256 7141812da1d25b5b14b12c2570c5958d7ca573a1c09535695b582bea7ae0df5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for flet_printing-0.2.0-py3-none-any.whl:

Publisher: publish.yml on aiseed-dev/flet-printing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page