feat(app): add image input support and bump to 1.5.0
Allow PNG/JPG/TIFF/BMP/GIF/WebP alongside PDF for preview and DXF conversion. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
19696937df
commit
2c9829ef8c
9 files changed
+88
-28
No files matched your search
@@ -1,15 +1,15 @@
|
|||||||
# PDF to DXF Converter
|
# PDF / Image to DXF Converter
|
||||||
|
|
||||||
Windows desktop app that converts PDF drawings to **DXF** for BricsCAD (and other CAD software), with a live page preview. Optionally saves **DWG** through your installed BricsCAD.
|
Windows desktop app that converts PDF and image drawings to **DXF** for BricsCAD (and other CAD software), with a live preview. Optionally saves **DWG** through your installed BricsCAD.
|
||||||
|
|
||||||
**License:** [MIT](LICENSE)
|
**License:** [MIT](LICENSE)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- PDF page preview with previous/next navigation
|
- PDF and image preview (`PNG`, `JPG`, `TIFF`, `BMP`, `GIF`, `WebP`)
|
||||||
- Conversion modes: **auto**, **vector**, **vectorize**, **raster**
|
- Conversion modes: **auto**, **vector**, **vectorize**, **raster**
|
||||||
- True vector PDFs → editable lines/polylines/text in DXF
|
- True vector PDFs → editable lines/polylines/text in DXF
|
||||||
- Flattened / image-only drawing PDFs → traced to editable polylines (`vectorize`)
|
- Image files and flattened PDFs → traced to editable polylines (`vectorize`)
|
||||||
- Optional raster underlay mode for scans you want as images
|
- Optional raster underlay mode for scans you want as images
|
||||||
- Optional DWG export via BricsCAD `SAVEAS`
|
- Optional DWG export via BricsCAD `SAVEAS`
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ Optional only: BricsCAD for DWG save.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
1. Click **Open PDF…** and pick a file
|
1. Click **Open PDF or Image…** and pick a supported file
|
||||||
2. Preview pages with ◀ / ▶
|
2. Preview pages with ◀ / ▶
|
||||||
3. Choose mode (`auto` recommended), pages, and scale (1.0 = PDF size; use your own multiplier)
|
3. Choose mode (`auto` recommended), pages, and scale (1.0 = PDF size; use your own multiplier)
|
||||||
4. Click **Convert & Save…** — review each page (vector / image / vectorize / skip), then pick the DXF path
|
4. Click **Convert & Save…** — review each page (vector / image / vectorize / skip), then pick the DXF path
|
||||||
@@ -61,9 +61,9 @@ Optional only: BricsCAD for DWG save.
|
|||||||
|
|
||||||
| Mode | Best for | Result |
|
| Mode | Best for | Result |
|
||||||
|------|----------|--------|
|
|------|----------|--------|
|
||||||
| `auto` | Mixed PDFs | Native vectors when present; traces image-only drawing pages |
|
| `auto` | PDFs and images | Native vectors when present; traces image-only inputs |
|
||||||
| `vector` | CAD-exported PDFs | Editable geometry and text (traces if the page is only a bitmap) |
|
| `vector` | CAD-exported PDFs | Editable geometry and text (traces if the page is only a bitmap) |
|
||||||
| `vectorize` | Flattened / printed drawing PDFs | Raster-to-vector polylines (set **Trace detail** to high/maximum) |
|
| `vectorize` | Images and flattened drawing PDFs | Raster-to-vector polylines (set **Trace detail** to high/maximum) |
|
||||||
| `raster` | Photos / underlays | Full-page image in the DXF |
|
| `raster` | Photos / underlays | Full-page image in the DXF |
|
||||||
|
|
||||||
### BricsCAD DWG
|
### BricsCAD DWG
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
"""PDF to DXF converter application package."""
|
"""PDF to DXF converter application package."""
|
||||||
|
|
||||||
__version__ = "1.4.1"
|
__version__ = "1.5.0"
|
||||||
+5
-4
@@ -13,6 +13,7 @@ import ezdxf
|
|||||||
import fitz
|
import fitz
|
||||||
from ezdxf import units
|
from ezdxf import units
|
||||||
|
|
||||||
|
from app.input_document import open_input_document
|
||||||
from app.raster_vectorize import vectorize_page
|
from app.raster_vectorize import vectorize_page
|
||||||
|
|
||||||
|
|
||||||
@@ -142,13 +143,13 @@ def classify_page(
|
|||||||
|
|
||||||
|
|
||||||
def classify_pdf_pages(
|
def classify_pdf_pages(
|
||||||
pdf_path: str | Path,
|
input_path: str | Path,
|
||||||
pages: list[int] | None = None,
|
pages: list[int] | None = None,
|
||||||
*,
|
*,
|
||||||
vector_threshold: int = 20,
|
vector_threshold: int = 20,
|
||||||
) -> list[PageClassification]:
|
) -> list[PageClassification]:
|
||||||
"""Classify selected pages of a PDF for the pre-convert review dialog."""
|
"""Classify selected pages of a PDF or image for pre-convert review."""
|
||||||
pdf = fitz.open(str(pdf_path))
|
pdf = open_input_document(input_path)
|
||||||
try:
|
try:
|
||||||
indices = _page_indices(pdf, pages)
|
indices = _page_indices(pdf, pages)
|
||||||
return [
|
return [
|
||||||
@@ -1134,7 +1135,7 @@ def convert_pdf_to_dxf(
|
|||||||
pdf_path = Path(pdf_path)
|
pdf_path = Path(pdf_path)
|
||||||
output_path = Path(output_path)
|
output_path = Path(output_path)
|
||||||
|
|
||||||
pdf = fitz.open(str(pdf_path))
|
pdf = open_input_document(pdf_path)
|
||||||
try:
|
try:
|
||||||
indices = _page_indices(pdf, options.pages)
|
indices = _page_indices(pdf, options.pages)
|
||||||
if not indices:
|
if not indices:
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
"""Open supported PDF and image inputs as PDF documents."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import fitz
|
||||||
|
|
||||||
|
|
||||||
|
PDF_EXTENSIONS = {".pdf"}
|
||||||
|
IMAGE_EXTENSIONS = {
|
||||||
|
".bmp",
|
||||||
|
".gif",
|
||||||
|
".jpeg",
|
||||||
|
".jpg",
|
||||||
|
".png",
|
||||||
|
".tif",
|
||||||
|
".tiff",
|
||||||
|
".webp",
|
||||||
|
}
|
||||||
|
SUPPORTED_EXTENSIONS = PDF_EXTENSIONS | IMAGE_EXTENSIONS
|
||||||
|
|
||||||
|
|
||||||
|
def is_image_input(path: str | Path) -> bool:
|
||||||
|
"""Return whether the selected input is a supported image."""
|
||||||
|
return Path(path).suffix.lower() in IMAGE_EXTENSIONS
|
||||||
|
|
||||||
|
|
||||||
|
def open_input_document(path: str | Path) -> fitz.Document:
|
||||||
|
"""Open a PDF directly or wrap an image in an in-memory PDF."""
|
||||||
|
input_path = Path(path)
|
||||||
|
extension = input_path.suffix.lower()
|
||||||
|
if extension not in SUPPORTED_EXTENSIONS:
|
||||||
|
supported = ", ".join(sorted(SUPPORTED_EXTENSIONS))
|
||||||
|
raise ValueError(f"Unsupported input type. Supported: {supported}")
|
||||||
|
|
||||||
|
document = fitz.open(str(input_path))
|
||||||
|
if extension in PDF_EXTENSIONS:
|
||||||
|
return document
|
||||||
|
|
||||||
|
try:
|
||||||
|
pdf_bytes = document.convert_to_pdf()
|
||||||
|
finally:
|
||||||
|
document.close()
|
||||||
|
return fitz.open("pdf", pdf_bytes)
|
||||||
+4
-1
@@ -7,9 +7,12 @@ from pathlib import Path
|
|||||||
import fitz
|
import fitz
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
from app.input_document import open_input_document
|
||||||
|
|
||||||
|
|
||||||
def open_document(path: str | Path) -> fitz.Document:
|
def open_document(path: str | Path) -> fitz.Document:
|
||||||
return fitz.open(str(path))
|
"""Open a supported PDF or image for preview."""
|
||||||
|
return open_input_document(path)
|
||||||
|
|
||||||
|
|
||||||
def page_count(doc: fitz.Document) -> int:
|
def page_count(doc: fitz.Document) -> int:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Main CustomTkinter UI for PDF to DXF conversion."""
|
"""Main CustomTkinter UI for PDF/image to DXF conversion."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ from app.converter import (
|
|||||||
convert_pdf_to_dxf,
|
convert_pdf_to_dxf,
|
||||||
parse_page_range,
|
parse_page_range,
|
||||||
)
|
)
|
||||||
|
from app.input_document import IMAGE_EXTENSIONS, is_image_input
|
||||||
from app.page_review import ask_page_modes
|
from app.page_review import ask_page_modes
|
||||||
from app.pdf_preview import close_document, open_document, page_count, render_page
|
from app.pdf_preview import close_document, open_document, page_count, render_page
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ ctk.set_default_color_theme("blue")
|
|||||||
class App(ctk.CTk):
|
class App(ctk.CTk):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.title(f"PDF to DXF Converter v{__version__}")
|
self.title(f"PDF / Image to DXF Converter v{__version__}")
|
||||||
self.geometry("1100x720")
|
self.geometry("1100x720")
|
||||||
self.minsize(800, 520)
|
self.minsize(800, 520)
|
||||||
|
|
||||||
@@ -66,19 +67,19 @@ class App(ctk.CTk):
|
|||||||
|
|
||||||
ctk.CTkLabel(
|
ctk.CTkLabel(
|
||||||
scroll,
|
scroll,
|
||||||
text="PDF → DXF",
|
text="PDF / Image → DXF",
|
||||||
font=ctk.CTkFont(size=22, weight="bold"),
|
font=ctk.CTkFont(size=22, weight="bold"),
|
||||||
).pack(padx=16, pady=(16, 4), anchor="w", fill="x")
|
).pack(padx=16, pady=(16, 4), anchor="w", fill="x")
|
||||||
|
|
||||||
self._add_wrap_label(
|
self._add_wrap_label(
|
||||||
scroll,
|
scroll,
|
||||||
"Preview & convert for BricsCAD",
|
"Preview and convert drawings for BricsCAD",
|
||||||
font=ctk.CTkFont(size=12),
|
font=ctk.CTkFont(size=12),
|
||||||
text_color=("gray40", "gray70"),
|
text_color=("gray40", "gray70"),
|
||||||
pady=(0, 12),
|
pady=(0, 12),
|
||||||
)
|
)
|
||||||
|
|
||||||
ctk.CTkButton(scroll, text="Open PDF…", command=self._open_pdf).pack(
|
ctk.CTkButton(scroll, text="Open PDF or Image…", command=self._open_pdf).pack(
|
||||||
padx=16, pady=6, fill="x"
|
padx=16, pady=6, fill="x"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -220,7 +221,7 @@ class App(ctk.CTk):
|
|||||||
|
|
||||||
self.preview_label = ctk.CTkLabel(
|
self.preview_label = ctk.CTkLabel(
|
||||||
self.preview_frame,
|
self.preview_frame,
|
||||||
text="Open a PDF to see a preview",
|
text="Open a PDF or image to see a preview",
|
||||||
text_color=("gray40", "gray60"),
|
text_color=("gray40", "gray60"),
|
||||||
)
|
)
|
||||||
self.preview_label.grid(row=0, column=0, sticky="nsew")
|
self.preview_label.grid(row=0, column=0, sticky="nsew")
|
||||||
@@ -307,8 +308,16 @@ class App(ctk.CTk):
|
|||||||
if self._busy:
|
if self._busy:
|
||||||
return
|
return
|
||||||
path = filedialog.askopenfilename(
|
path = filedialog.askopenfilename(
|
||||||
title="Open PDF",
|
title="Open PDF or Image",
|
||||||
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
|
filetypes=[
|
||||||
|
(
|
||||||
|
"PDF and image files",
|
||||||
|
"*.pdf *.png *.jpg *.jpeg *.tif *.tiff *.bmp *.gif *.webp",
|
||||||
|
),
|
||||||
|
("PDF files", "*.pdf"),
|
||||||
|
("Image files", " ".join(f"*{ext}" for ext in sorted(IMAGE_EXTENSIONS))),
|
||||||
|
("All files", "*.*"),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
@@ -319,7 +328,8 @@ class App(ctk.CTk):
|
|||||||
self._page_index = 0
|
self._page_index = 0
|
||||||
self.file_label.configure(text=self._pdf_path.name)
|
self.file_label.configure(text=self._pdf_path.name)
|
||||||
self._refresh_preview()
|
self._refresh_preview()
|
||||||
self._set_status(f"Loaded {page_count(self._doc)} page(s)")
|
input_kind = "image" if is_image_input(path) else "PDF"
|
||||||
|
self._set_status(f"Loaded {input_kind}: {page_count(self._doc)} page(s)")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
messagebox.showerror("Open failed", str(exc))
|
messagebox.showerror("Open failed", str(exc))
|
||||||
self._set_status("Failed to open PDF")
|
self._set_status("Failed to open PDF")
|
||||||
@@ -373,7 +383,7 @@ class App(ctk.CTk):
|
|||||||
if self._busy:
|
if self._busy:
|
||||||
return
|
return
|
||||||
if self._doc is None or self._pdf_path is None:
|
if self._doc is None or self._pdf_path is None:
|
||||||
messagebox.showinfo("No PDF", "Open a PDF file first.")
|
messagebox.showinfo("No input", "Open a PDF or image file first.")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ Write-Host "Building application (folder payload)..."
|
|||||||
--hidden-import app.pdf_preview `
|
--hidden-import app.pdf_preview `
|
||||||
--hidden-import app.ocr_support `
|
--hidden-import app.ocr_support `
|
||||||
--hidden-import app.page_review `
|
--hidden-import app.page_review `
|
||||||
|
--hidden-import app.input_document `
|
||||||
main.py
|
main.py
|
||||||
|
|
||||||
$AppExe = Join-Path $AppDistDir "$AppDistName.exe"
|
$AppExe = Join-Path $AppDistDir "$AppDistName.exe"
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ import zipfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Keep in sync with app.__version__
|
# Keep in sync with app.__version__
|
||||||
APP_VERSION = "1.4.1"
|
APP_VERSION = "1.5.0"
|
||||||
APP_NAME = "PDF_to_DXF"
|
APP_NAME = "PDF_to_DXF"
|
||||||
PAYLOAD_NAME = "app_payload.zip"
|
PAYLOAD_NAME = "app_payload.zip"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
PDF to DXF Converter — single EXE
|
PDF / Image to DXF Converter — single EXE
|
||||||
=================================
|
=========================================
|
||||||
|
|
||||||
How to install on another PC
|
How to install on another PC
|
||||||
----------------------------
|
----------------------------
|
||||||
@@ -14,9 +14,9 @@ re-installs automatically.
|
|||||||
|
|
||||||
What works with nothing else installed
|
What works with nothing else installed
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
- Open PDF, preview pages
|
- Open and preview PDF or image files (PNG, JPG, TIFF, BMP, GIF, WebP)
|
||||||
- Convert to DXF (vector / vectorize / raster / auto)
|
- Convert to DXF (vector / vectorize / raster / auto)
|
||||||
- High-detail tracing of flattened drawing PDFs
|
- High-detail tracing of image files and flattened drawing PDFs
|
||||||
- OCR for outlined / non-selectable text (bundled language data)
|
- OCR for outlined / non-selectable text (bundled language data)
|
||||||
|
|
||||||
Optional (not required)
|
Optional (not required)
|
||||||
|
|||||||
Reference in new issue
Block a user