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. ReturnsFalseif 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54bd96700702705fa05dd3004045c9a916c007a94042f957217b1bea07b1ecf4
|
|
| MD5 |
9534ca2ef694c97cdcd66f2b26ce3d14
|
|
| BLAKE2b-256 |
dc8a18ca756f165c6541bef2f6445620de9ed51940d905c0bd0cb87887c3ca3f
|
Provenance
The following attestation bundles were made for flet_printing-0.2.0.tar.gz:
Publisher:
publish.yml on aiseed-dev/flet-printing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flet_printing-0.2.0.tar.gz -
Subject digest:
54bd96700702705fa05dd3004045c9a916c007a94042f957217b1bea07b1ecf4 - Sigstore transparency entry: 2166692487
- Sigstore integration time:
-
Permalink:
aiseed-dev/flet-printing@7f596b7f8120f33f471b400c1c72b410e7726afb -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/aiseed-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7f596b7f8120f33f471b400c1c72b410e7726afb -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d219c1861f979320a2ddeadddc83136e220275403aa5ef10c772984e4cce0b9
|
|
| MD5 |
cd87783f4a552a75a375150f3271acc0
|
|
| BLAKE2b-256 |
7141812da1d25b5b14b12c2570c5958d7ca573a1c09535695b582bea7ae0df5c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flet_printing-0.2.0-py3-none-any.whl -
Subject digest:
4d219c1861f979320a2ddeadddc83136e220275403aa5ef10c772984e4cce0b9 - Sigstore transparency entry: 2166692493
- Sigstore integration time:
-
Permalink:
aiseed-dev/flet-printing@7f596b7f8120f33f471b400c1c72b410e7726afb -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/aiseed-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7f596b7f8120f33f471b400c1c72b410e7726afb -
Trigger Event:
push
-
Statement type: