VICON: Sistema de Visión configurable V1.0
Trabajo Fin de Master Carlos Manuel Gomez Jimenez
Loading...
Searching...
No Matches
convertidor_svg2pdf.py
Go to the documentation of this file.
1import tkinter as tk
2from tkinter import filedialog, messagebox
3import subprocess
4import os
5
6class SVGConverterApp:
7 def __init__(self, root):
8 self.root = root
9 self.root.title("Inkscape SVG to PDF Converter")
10 self.root.geometry("500x300")
11 self.root.configure(bg="#f0f0f0")
12
14
15 # Interfaz
16 self.label = tk.Label(root, text="Convertidor de SVG a PDF", font=("Arial", 16, "bold"), bg="#f0f0f0")
17 self.label.pack(pady=20)
18
19 self.btn_select = tk.Button(root, text="Seleccionar archivos SVG", command=self.select_files, width=25, bg="#007acc", fg="white")
20 self.btn_select.pack(pady=10)
21
22 self.files_label = tk.Label(root, text="No hay archivos seleccionados", bg="#f0f0f0", fg="#555")
23 self.files_label.pack()
24
25 self.btn_convert = tk.Button(root, text="Convertir a PDF", command=self.convert_files, width=25, bg="#28a745", fg="white", state="disabled")
26 self.btn_convert.pack(pady=20)
27
28 def select_files(self):
29 files = filedialog.askopenfilenames(title="Selecciona archivos SVG", filetypes=[("Archivos SVG", "*.svg")])
30 if files:
32 self.files_label.config(text=f"{len(self.selected_files)} archivos listos.")
33 self.btn_convert.config(state="normal")
34
35 def convert_files(self):
36 output_dir = filedialog.askdirectory(title="Selecciona carpeta de destino")
37 if not output_dir:
38 return
39
40 success_count = 0
41 for svg_path in self.selected_filesselected_files:
42 file_name = os.path.splitext(os.path.basename(svg_path))[0]
43 pdf_path = os.path.join(output_dir, f"{file_name}.pdf")
44
45 # Comando de Inkscape para exportar
46 # Usamos la sintaxis moderna de Inkscape 1.x
47 command = [
48 "inkscape",
49 svg_path,
50 "--export-type=pdf",
51 f"--export-filename={pdf_path}"
52 ]
53
54 try:
55 # Ejecutamos en segundo plano sin abrir ventana de consola
56 subprocess.run(command, check=True, creationflags=subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0)
57 success_count += 1
58 except Exception as e:
59 messagebox.showerror("Error", f"No se pudo convertir {file_name}: {str(e)}")
60
61 messagebox.showinfo("Proceso terminado", f"Se han convertido {success_count} archivos con éxito.")
62 self.reset_ui()
63
64 def reset_ui(self):
66 self.files_label.config(text="No hay archivos seleccionados")
67 self.btn_convert.config(state="disabled")
68
69if __name__ == "__main__":
70 root = tk.Tk()
71 app = SVGConverterApp(root)
72 root.mainloop()