FletPdfviewer control for Flet
Project description
PDF Viewer for Flet
https://github.com/user-attachments/assets/9b30611e-b8b4-45fa-a8b6-a7a50d9a234d
PdfViewer is a powerful PDF viewer component for Flet applications. It provides a feature-rich interface for displaying and interacting with PDF documents in your Flet applications.
Installation
pip install flet_pdfviewer
Basic Usage
Here's a simple example of how to use the FletPdfviewer component:
import flet as ft
from flet_pdfviewer import FletPdfviewer
def main(page: ft.Page):
pdf_viewer = FletPdfviewer(
source="https://example.com/sample.pdf",
source_type="network",
show_bookmark=True,
enable_double_tap_zooming=True
)
page.add(pdf_viewer)
ft.app(target=main)
Advanced Example
Here's a more comprehensive example that demonstrates various features:
import flet as ft
from flet_pdfviewer import FletPdfviewer
def main(page: ft.Page):
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
# Create PDF viewer with event handling
def handle_zoom_changed(e):
print(f"Zoom level changed: {e}")
pdf_viewer = FletPdfviewer(
source="https://example.com/sample.pdf",
source_type="network",
show_bookmark=True,
enable_double_tap_zooming=True,
on_zoom_level_changed=handle_zoom_changed,
password="optional_password", # If PDF is password-protected
expand=True
)
# Add controls for PDF interaction
def jump_to_page_3(e):
pdf_viewer.jump_to_page(3)
def set_zoom_2x(e):
pdf_viewer.set_zoom_level(2.0)
page.add(
pdf_viewer,
ft.Row(
[ft.ElevatedButton("Go to Page 3", on_click=jump_to_page_3),
ft.ElevatedButton("Zoom 2x", on_click=set_zoom_2x)]
)
)
ft.app(target=main)
API Reference
Constructor Parameters
source(Optional[str]): The source of the PDF document. Can be a URL, file path, or asset path.source_type(Optional[str]): Type of the source. Can be "network", "file", or "asset". Default is "network".show_bookmark(Optional[bool]): Whether to show the bookmark panel. Default is True.memory_bytes(Optional[str]): PDF data as bytes in memory.password(Optional[str]): Password for protected PDF documents.enable_double_tap_zooming(Optional[bool]): Enable zooming with double tap. Default is True.on_zoom_level_changed(Optional[Callable]): Callback function for zoom level changes.
Standard Control Properties
width(OptionalNumber): Control width.height(OptionalNumber): Control height.expand(Optional[bool]): Whether the control should expand to fill available space.opacity(OptionalNumber): Control opacity.tooltip(Optional[str]): Tooltip text.visible(Optional[bool]): Control visibility.
Properties
source: Get or set the PDF source.source_type: Get or set the source type ("network", "file", "asset").show_bookmark: Get or set bookmark panel visibility.memory_bytes: Get or set PDF data in memory.password: Get or set PDF password.enable_double_tap_zooming: Get or set double tap zooming.
Methods
open_bookmark_view(): Opens the bookmark view.jump_to_page(page_number: int): Jumps to the specified page number.set_zoom_level(zoom_level: float): Sets the zoom level (between 1.0 and 3.0).get_current_page() -> int: Gets the current page number (async).get_current_zoom_level() -> float: Gets the current zoom level (async).get_total_pages() -> int: Gets the total number of pages (async).
Events
on_zoom_level_changed: Triggered when zoom level changes.
Notes
- For network PDFs, ensure the URL is accessible and the PDF is not blocked by CORS policies.
- Password-protected PDFs require the correct password to be set before viewing.
- Zoom levels are typically constrained between 1.0 and 3.0.
- Async methods should be awaited when called.
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_pdfviewer-0.1.0.tar.gz.
File metadata
- Download URL: flet_pdfviewer-0.1.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
871502fac04cfdf7386173b04cf4a402137936ae2d8e4eb15fae947bac8d3db7
|
|
| MD5 |
f50d442667fdd1bab096e9b494f4c179
|
|
| BLAKE2b-256 |
8fa4994c022e3d58cb97af4a18a8a7e47a5b767d5028224a9f0316b6bc04e706
|
File details
Details for the file flet_pdfviewer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flet_pdfviewer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99dff3e6991aece4cc8fa5ac8dd985f4e19b1163f52e848658931bd972833961
|
|
| MD5 |
42f08219d4943a1537f56e57adeddca6
|
|
| BLAKE2b-256 |
5dd0c84a1fb773e3c31c7f5f553fdfb3b185ff89c16c583a5d0f41734b2d5474
|