Image to PDF Converter (pdfforge)
様々な形式の画像を高品質なPDFに変換するPythonライブラリです。バッチ変換やメタデータ付与、コマンドライン操作、設定ファイルによるカスタマイズなど、実用的な機能を多数搭載しています。
特徴
- 複数の画像を1つのPDFに結合
- 様々な画像形式に対応(PNG, JPEG, BMP, GIF, TIFF, WebP, HEIC)
- 画像の前処理機能
- リサイズ
- 回転
- フィルター適用(ぼかし、シャープ化、エッジ検出など)
- 色空間変換
- 進捗表示
- エラーハンドリング
- 設定ファイルによるカスタマイズ
- コマンドラインインターフェース
インストール
pip install pdfforge
基本的な使い方
コマンドラインから
# 基本的な使用方法
pdfforge input/*.jpg output.pdf
# 画像のリサイズを指定
pdfforge input/*.jpg output.pdf --width 800 --height 600
# 画像の回転を指定
pdfforge input/*.jpg output.pdf --rotate 90
# フィルターを適用
pdfforge input/*.jpg output.pdf --filter blur
# 複数のオプションを組み合わせ
pdfforge input/*.jpg output.pdf --width 800 --rotate 90 --filter sharpen
Pythonコードから
from pdfforge import ImageToPDF
# 基本的な使用方法
converter = ImageToPDF()
converter.convert("input/*.jpg", "output.pdf")
# 画像のリサイズを指定
converter = ImageToPDF(width=800, height=600)
converter.convert("input/*.jpg", "output.pdf")
# 画像の回転を指定
converter = ImageToPDF(rotate=90)
converter.convert("input/*.jpg", "output.pdf")
# フィルターを適用
from PIL import ImageFilter
converter = ImageToPDF(filter=ImageFilter.BLUR)
converter.convert("input/*.jpg", "output.pdf")
# 複数のオプションを組み合わせ
converter = ImageToPDF(
width=800,
height=600,
rotate=90,
filter=ImageFilter.SHARPEN
)
converter.convert("input/*.jpg", "output.pdf")
高度な使い方
設定ファイルの使用
~/.pdfforge/config.jsonに設定ファイルを作成することで、デフォルトの設定をカスタマイズできます:
{
"width": 800,
"height": 600,
"rotate": 0,
"filter": "none",
"output_format": "PDF",
"compression_quality": 85
}
エラーハンドリング
from pdfforge import ImageToPDF, ConversionError
try:
converter = ImageToPDF()
converter.convert("input/*.jpg", "output.pdf")
except ConversionError as e:
print(f"変換エラー: {e}")
進捗表示のカスタマイズ
from pdfforge import ImageToPDF
from tqdm import tqdm
converter = ImageToPDF(progress_bar=tqdm)
converter.convert("input/*.jpg", "output.pdf")
サポートされている画像形式
- PNG
- JPEG
- BMP
- GIF
- TIFF
- WebP
- HEIC
サポートされているフィルター
- ぼかし(Blur)
- シャープ化(Sharpen)
- エッジ検出(Edge Detection)
- 輪郭検出(Contour)
- エンボス(Emboss)
- スムージング(Smooth)
ライセンス
MITライセンスの下で公開されています。詳細はLICENSEファイルを参照してください。
貢献
- このリポジトリをフォーク
- 新しいブランチを作成 (
git checkout -b feature/amazing-feature) - 変更をコミット (
git commit -m 'Add some amazing feature') - ブランチにプッシュ (
git push origin feature/amazing-feature) - プルリクエストを作成
作者
- tikisan - 初期開発者
謝辞
注意事項
- 大量の画像を処理する場合は、メモリ使用量に注意してください
- HEIC形式の画像を処理するには、追加のライブラリが必要な場合があります
- 一部の画像形式は、Pillowのインストール時に追加の依存関係が必要な場合があります
トラブルシューティング
一般的な問題
-
メモリエラー
- 画像のサイズを小さくする
- バッチ処理を使用する
- システムのメモリを増やす
-
画像形式のサポート
- Pillowが正しくインストールされているか確認
- 必要な追加ライブラリをインストール
-
パフォーマンスの問題
- 画像の前処理を最適化
- マルチスレッド処理を検討
- バッチサイズを調整
よくある質問
-
Q: 大量の画像を処理するには? A: バッチ処理を使用し、適切なバッチサイズを設定してください。
-
Q: 特定の画像形式がサポートされていない場合は? A: Pillowのドキュメントを確認し、必要な追加ライブラリをインストールしてください。
-
Q: メモリ使用量を最適化するには? A: 画像のサイズを小さくし、バッチ処理を使用してください。
開発者向け情報
テスト
# すべてのテストを実行
pytest
# 特定のテストを実行
pytest tests/test_core.py
# カバレッジレポートを生成
pytest --cov=pdfforge tests/
コードスタイル
このプロジェクトはPEP 8に従っています。
ドキュメント
# ドキュメントを生成
cd docs
make html
更新履歴
0.1.0 (2024-03-XX)
- 初期リリース
- 基本的な画像からPDFへの変換機能
- 画像の前処理機能
- コマンドラインインターフェース
- 設定ファイルサポート
ロードマップ
- マルチスレッド処理のサポート
- より多くの画像形式のサポート
- PDFの暗号化機能
- 画像の自動最適化
- バッチ処理の改善
- より詳細な進捗表示
- エラーログの強化
- ユニットテストの追加
- ドキュメントの拡充
- パフォーマンスの最適化
Metadata
Release files for pdfforge 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pdfforge-1.0.1.tar.gz | 17.4 kB | Without provenance | Details for pdfforge-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pdfforge-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pdfforge-1.0.1-py3-none-any.whl |
Total release size: 35.2 kB
Release files / pdfforge-1.0.1.tar.gz
| Download URL | pdfforge-1.0.1.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f950126dce2cbd30b8dde47be76018d191271fd1de7750e9753822f6abb5b478
|
|
BLAKE2b-256 checksum How to use checksums |
292cb9371ed48fd772cb7bf9df21c512a8eb915571d1d42618f1805d9ce5c55b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / pdfforge-1.0.1-py3-none-any.whl
| Download URL | pdfforge-1.0.1-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6db373e6a759a7bae438c832abc165b5df1205c560fb326a7205bd2d1afe414
|
|
BLAKE2b-256 checksum How to use checksums |
eb07174f6e8114a2242cf0fac7e946ea832336ffb759cc169b970966782cb60c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for pdfforge 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.