Name | universal-printer JSON |
Version |
2.0.0
JSON |
| download |
home_page | None |
Summary | Universal cross-platform printer supporting text and all file types with PDF fallback - pure Python standard library |
upload_time | 2025-08-04 05:33:06 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | None |
keywords |
printing
pdf
cross-platform
documents
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Universal Printer
A powerful cross-platform document printing library supporting text and all file types with PDF fallback, using only Python's standard library.
## Features
- **Universal File Support**: Print any file type (PDF, DOC, TXT, images, HTML, etc.)
- **Cross-platform**: Works on Windows, macOS, and Linux
- **Dependency-free**: Uses only Python standard library
- **Smart PDF fallback**: Automatically creates a PDF if printing fails
- **File type detection**: Automatic MIME type detection and handling
- **Simple API**: Easy to use with minimal setup
- **Multiple convenience methods**: `print_text()`, `print_file()`, `print_document()`
## Installation
```bash
pip install universal-printer
```
## Quick Start
```python
from universal_printer import DocumentPrinter
# Create printer instance
printer = DocumentPrinter()
# Print text content
success, message, pdf_path = printer.print_text(
"Hello, World!\nThis is a test document.",
fallback_to_pdf=True
)
# Print any file type
success, message, pdf_path = printer.print_file(
"/path/to/document.pdf", # or .docx, .jpg, .html, etc.
fallback_to_pdf=True
)
if success:
print("Document printed successfully!")
else:
print(f"Printing failed: {message}")
if pdf_path:
print(f"PDF fallback saved to: {pdf_path}")
```
## Supported File Types
The library can handle any file type, with optimized support for:
- **Documents**: `.pdf`, `.doc`, `.docx`, `.rtf`, `.odt`
- **Text files**: `.txt`, `.csv`, `.json`, `.xml`, `.html`, `.htm`
- **Images**: `.jpg`, `.jpeg`, `.png`, `.gif`, `.bmp`, `.tiff`
- **Any other file type**: Will attempt to print or create PDF representation
## API Reference
### DocumentPrinter
#### `__init__()`
Creates a new DocumentPrinter instance with automatic file type detection.
#### `print_document(content_or_path, printer_name=None, fallback_to_pdf=True, pdf_filename=None)`
Universal method to print text content or any file type.
**Parameters:**
- `content_or_path` (str): Text content or path to any file type
- `printer_name` (str, optional): Name of printer to use, or "PDF" for print-to-PDF
- `fallback_to_pdf` (bool): Create PDF if printing fails (default: True)
- `pdf_filename` (str, optional): Custom filename for PDF fallback
**Returns:**
- `tuple`: (success: bool, message: str, pdf_path: str or None)
#### `print_text(text, printer_name=None, fallback_to_pdf=True, pdf_filename=None)`
Convenience method specifically for printing text content.
#### `print_file(file_path, printer_name=None, fallback_to_pdf=True, pdf_filename=None)`
Convenience method specifically for printing files.
#### `get_supported_file_types()`
Returns set of file extensions optimized for direct printing.
#### `is_file_printable(file_path)`
Check if a file type is directly supported for printing.
## Examples
### Print Text Content
```python
from universal_printer import DocumentPrinter
printer = DocumentPrinter()
# Simple text printing
success, msg, pdf = printer.print_text("Hello, World!")
print(f"Result: {success}, Message: {msg}")
# Multi-line text with custom PDF name
text_content = """
Invoice #12345
Date: 2024-01-01
Amount: $100.00
Thank you for your business!
"""
success, msg, pdf = printer.print_text(
text_content,
pdf_filename="invoice_12345.pdf"
)
```
### Print Various File Types
```python
# Print a PDF document
success, msg, pdf = printer.print_file("/path/to/document.pdf")
# Print a Word document
success, msg, pdf = printer.print_file("/path/to/report.docx")
# Print an image
success, msg, pdf = printer.print_file("/path/to/photo.jpg")
# Print HTML file
success, msg, pdf = printer.print_file("/path/to/webpage.html")
# Print CSV data
success, msg, pdf = printer.print_file("/path/to/data.csv")
```
### Advanced Usage
```python
# Check if file type is supported
if printer.is_file_printable("/path/to/document.pdf"):
print("PDF files are directly printable")
# Get all supported file types
supported_types = printer.get_supported_file_types()
print(f"Supported types: {supported_types}")
# Print to specific printer
success, msg, pdf = printer.print_document(
"Important memo",
printer_name="HP_LaserJet_Pro"
)
# Print to PDF (bypass physical printer)
success, msg, pdf = printer.print_document(
"Save as PDF",
printer_name="PDF",
pdf_filename="saved_document.pdf"
)
```
### Error Handling and File Detection
```python
# The library automatically detects file types
success, msg, pdf = printer.print_file("unknown_file.xyz")
# Will attempt to print or create PDF representation
# Handle binary files gracefully
success, msg, pdf = printer.print_file("/path/to/program.exe")
# Creates PDF with file information for binary files
# Disable PDF fallback for testing
success, msg, pdf = printer.print_text(
"Print or fail",
fallback_to_pdf=False
)
if not success:
print("Printing failed and no PDF was created")
```
## Platform-Specific Behavior
### Windows
- Uses `rundll32.exe` with shell print verb for all file types
- Falls back to Notepad for text files if needed
- Supports "Microsoft Print to PDF" printer
- Handles Office documents, images, and PDFs natively
### macOS/Linux
- Uses `lp` command (CUPS) for all file types
- Supports print-to-PDF with CUPS
- Handles various file formats through system print drivers
- Requires printer to be configured in system
## File Type Detection
The library includes intelligent file type detection:
- **MIME type detection**: Automatic detection using Python's `mimetypes`
- **Extension-based fallback**: Uses file extensions when MIME detection fails
- **Binary file handling**: Creates descriptive PDF for non-text binary files
- **Encoding detection**: Handles various text encodings (UTF-8, Latin-1)
## PDF Fallback Features
Enhanced PDF fallback system:
- **Smart content handling**: Different handling for text vs binary files
- **File information**: Includes file metadata in PDF for binary files
- **Improved formatting**: Better text layout and formatting
- **Error recovery**: Multiple fallback levels for maximum reliability
## Requirements
- Python 3.7+
- No external dependencies
- Works on Windows, macOS, and Linux
## License
MIT License - see LICENSE file for details.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## Changelog
### 2.0.0
- **MAJOR UPDATE**: Universal file type support
- Added support for all file types (PDF, DOC, images, etc.)
- New convenience methods: `print_text()`, `print_file()`
- Automatic file type detection and MIME type handling
- Enhanced PDF fallback with better formatting
- Improved error handling and binary file support
- Better cross-platform compatibility
- Added file type checking utilities
### 0.1.0
- Initial release
- Basic cross-platform printing
- PDF fallback functionality
- Support for text content and existing files
Raw data
{
"_id": null,
"home_page": null,
"name": "universal-printer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "printing, pdf, cross-platform, documents",
"author": null,
"author_email": "Sharath Kumar Daroor <sharathkumardaroor@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/68/6c/1c5e6e6ed07a67b64c4083dd586c603bbd1e6b94a15ed0fdffa9f6e1e9c3/universal_printer-2.0.0.tar.gz",
"platform": null,
"description": "# Universal Printer\n\nA powerful cross-platform document printing library supporting text and all file types with PDF fallback, using only Python's standard library.\n\n## Features\n\n- **Universal File Support**: Print any file type (PDF, DOC, TXT, images, HTML, etc.)\n- **Cross-platform**: Works on Windows, macOS, and Linux\n- **Dependency-free**: Uses only Python standard library\n- **Smart PDF fallback**: Automatically creates a PDF if printing fails\n- **File type detection**: Automatic MIME type detection and handling\n- **Simple API**: Easy to use with minimal setup\n- **Multiple convenience methods**: `print_text()`, `print_file()`, `print_document()`\n\n## Installation\n\n```bash\npip install universal-printer\n```\n\n## Quick Start\n\n```python\nfrom universal_printer import DocumentPrinter\n\n# Create printer instance\nprinter = DocumentPrinter()\n\n# Print text content\nsuccess, message, pdf_path = printer.print_text(\n \"Hello, World!\\nThis is a test document.\",\n fallback_to_pdf=True\n)\n\n# Print any file type\nsuccess, message, pdf_path = printer.print_file(\n \"/path/to/document.pdf\", # or .docx, .jpg, .html, etc.\n fallback_to_pdf=True\n)\n\nif success:\n print(\"Document printed successfully!\")\nelse:\n print(f\"Printing failed: {message}\")\n if pdf_path:\n print(f\"PDF fallback saved to: {pdf_path}\")\n```\n\n## Supported File Types\n\nThe library can handle any file type, with optimized support for:\n\n- **Documents**: `.pdf`, `.doc`, `.docx`, `.rtf`, `.odt`\n- **Text files**: `.txt`, `.csv`, `.json`, `.xml`, `.html`, `.htm`\n- **Images**: `.jpg`, `.jpeg`, `.png`, `.gif`, `.bmp`, `.tiff`\n- **Any other file type**: Will attempt to print or create PDF representation\n\n## API Reference\n\n### DocumentPrinter\n\n#### `__init__()`\nCreates a new DocumentPrinter instance with automatic file type detection.\n\n#### `print_document(content_or_path, printer_name=None, fallback_to_pdf=True, pdf_filename=None)`\nUniversal method to print text content or any file type.\n\n**Parameters:**\n- `content_or_path` (str): Text content or path to any file type\n- `printer_name` (str, optional): Name of printer to use, or \"PDF\" for print-to-PDF\n- `fallback_to_pdf` (bool): Create PDF if printing fails (default: True)\n- `pdf_filename` (str, optional): Custom filename for PDF fallback\n\n**Returns:**\n- `tuple`: (success: bool, message: str, pdf_path: str or None)\n\n#### `print_text(text, printer_name=None, fallback_to_pdf=True, pdf_filename=None)`\nConvenience method specifically for printing text content.\n\n#### `print_file(file_path, printer_name=None, fallback_to_pdf=True, pdf_filename=None)`\nConvenience method specifically for printing files.\n\n#### `get_supported_file_types()`\nReturns set of file extensions optimized for direct printing.\n\n#### `is_file_printable(file_path)`\nCheck if a file type is directly supported for printing.\n\n## Examples\n\n### Print Text Content\n\n```python\nfrom universal_printer import DocumentPrinter\n\nprinter = DocumentPrinter()\n\n# Simple text printing\nsuccess, msg, pdf = printer.print_text(\"Hello, World!\")\nprint(f\"Result: {success}, Message: {msg}\")\n\n# Multi-line text with custom PDF name\ntext_content = \"\"\"\nInvoice #12345\nDate: 2024-01-01\nAmount: $100.00\nThank you for your business!\n\"\"\"\nsuccess, msg, pdf = printer.print_text(\n text_content,\n pdf_filename=\"invoice_12345.pdf\"\n)\n```\n\n### Print Various File Types\n\n```python\n# Print a PDF document\nsuccess, msg, pdf = printer.print_file(\"/path/to/document.pdf\")\n\n# Print a Word document\nsuccess, msg, pdf = printer.print_file(\"/path/to/report.docx\")\n\n# Print an image\nsuccess, msg, pdf = printer.print_file(\"/path/to/photo.jpg\")\n\n# Print HTML file\nsuccess, msg, pdf = printer.print_file(\"/path/to/webpage.html\")\n\n# Print CSV data\nsuccess, msg, pdf = printer.print_file(\"/path/to/data.csv\")\n```\n\n### Advanced Usage\n\n```python\n# Check if file type is supported\nif printer.is_file_printable(\"/path/to/document.pdf\"):\n print(\"PDF files are directly printable\")\n\n# Get all supported file types\nsupported_types = printer.get_supported_file_types()\nprint(f\"Supported types: {supported_types}\")\n\n# Print to specific printer\nsuccess, msg, pdf = printer.print_document(\n \"Important memo\",\n printer_name=\"HP_LaserJet_Pro\"\n)\n\n# Print to PDF (bypass physical printer)\nsuccess, msg, pdf = printer.print_document(\n \"Save as PDF\",\n printer_name=\"PDF\",\n pdf_filename=\"saved_document.pdf\"\n)\n```\n\n### Error Handling and File Detection\n\n```python\n# The library automatically detects file types\nsuccess, msg, pdf = printer.print_file(\"unknown_file.xyz\")\n# Will attempt to print or create PDF representation\n\n# Handle binary files gracefully\nsuccess, msg, pdf = printer.print_file(\"/path/to/program.exe\")\n# Creates PDF with file information for binary files\n\n# Disable PDF fallback for testing\nsuccess, msg, pdf = printer.print_text(\n \"Print or fail\",\n fallback_to_pdf=False\n)\nif not success:\n print(\"Printing failed and no PDF was created\")\n```\n\n## Platform-Specific Behavior\n\n### Windows\n- Uses `rundll32.exe` with shell print verb for all file types\n- Falls back to Notepad for text files if needed\n- Supports \"Microsoft Print to PDF\" printer\n- Handles Office documents, images, and PDFs natively\n\n### macOS/Linux\n- Uses `lp` command (CUPS) for all file types\n- Supports print-to-PDF with CUPS\n- Handles various file formats through system print drivers\n- Requires printer to be configured in system\n\n## File Type Detection\n\nThe library includes intelligent file type detection:\n\n- **MIME type detection**: Automatic detection using Python's `mimetypes`\n- **Extension-based fallback**: Uses file extensions when MIME detection fails\n- **Binary file handling**: Creates descriptive PDF for non-text binary files\n- **Encoding detection**: Handles various text encodings (UTF-8, Latin-1)\n\n## PDF Fallback Features\n\nEnhanced PDF fallback system:\n\n- **Smart content handling**: Different handling for text vs binary files\n- **File information**: Includes file metadata in PDF for binary files\n- **Improved formatting**: Better text layout and formatting\n- **Error recovery**: Multiple fallback levels for maximum reliability\n\n## Requirements\n\n- Python 3.7+\n- No external dependencies\n- Works on Windows, macOS, and Linux\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Changelog\n\n### 2.0.0\n- **MAJOR UPDATE**: Universal file type support\n- Added support for all file types (PDF, DOC, images, etc.)\n- New convenience methods: `print_text()`, `print_file()`\n- Automatic file type detection and MIME type handling\n- Enhanced PDF fallback with better formatting\n- Improved error handling and binary file support\n- Better cross-platform compatibility\n- Added file type checking utilities\n\n### 0.1.0\n- Initial release\n- Basic cross-platform printing\n- PDF fallback functionality\n- Support for text content and existing files\n",
"bugtrack_url": null,
"license": null,
"summary": "Universal cross-platform printer supporting text and all file types with PDF fallback - pure Python standard library",
"version": "2.0.0",
"project_urls": {
"Bug Reports": "https://github.com/yourusername/universal-printer/issues",
"Homepage": "https://github.com/yourusername/universal-printer",
"Source": "https://github.com/yourusername/universal-printer"
},
"split_keywords": [
"printing",
" pdf",
" cross-platform",
" documents"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e6d656f088c77107c196d32567055e83ea92db8fea2399835defe2ad5f2e17e1",
"md5": "38d0c9b882175a5908eb6806e655f760",
"sha256": "41d6191ab118fa4e8adf4675c0fc1a8f5c40acdfb583c83b2663ee203bb6d7d8"
},
"downloads": -1,
"filename": "universal_printer-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "38d0c9b882175a5908eb6806e655f760",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9363,
"upload_time": "2025-08-04T05:33:04",
"upload_time_iso_8601": "2025-08-04T05:33:04.797566Z",
"url": "https://files.pythonhosted.org/packages/e6/d6/56f088c77107c196d32567055e83ea92db8fea2399835defe2ad5f2e17e1/universal_printer-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "686c1c5e6e6ed07a67b64c4083dd586c603bbd1e6b94a15ed0fdffa9f6e1e9c3",
"md5": "53de7e4e1995aba084cefb6afcf9ccb4",
"sha256": "1ab7a81654543a00f9aeb9e69a72fe0494c9b8505a4cb6e82a33f102d0abbe5e"
},
"downloads": -1,
"filename": "universal_printer-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "53de7e4e1995aba084cefb6afcf9ccb4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 13480,
"upload_time": "2025-08-04T05:33:06",
"upload_time_iso_8601": "2025-08-04T05:33:06.443511Z",
"url": "https://files.pythonhosted.org/packages/68/6c/1c5e6e6ed07a67b64c4083dd586c603bbd1e6b94a15ed0fdffa9f6e1e9c3/universal_printer-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-04 05:33:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yourusername",
"github_project": "universal-printer",
"github_not_found": true,
"lcname": "universal-printer"
}