diff --git a/apps/fronted/src/app/app/workbench/[id]/page.tsx b/apps/fronted/src/app/app/workbench/[id]/page.tsx index 054bc15..5258f6c 100644 --- a/apps/fronted/src/app/app/workbench/[id]/page.tsx +++ b/apps/fronted/src/app/app/workbench/[id]/page.tsx @@ -229,7 +229,7 @@ export default function Home() { return (
edu.visible); return ( = ({ return ( { const styleCache = new Map(); @@ -70,9 +76,11 @@ const optimizeImages = async (element: HTMLElement) => { const PdfExport = () => { const [isExporting, setIsExporting] = useState(false); + const [isExportingJson, setIsExportingJson] = useState(false); const { activeResume } = useResumeStore(); const { globalSettings = {}, title } = activeResume || {}; const t = useTranslations("pdfExport"); + const printFrameRef = useRef(null); const handleExport = async () => { const exportStartTime = performance.now(); @@ -131,22 +139,200 @@ const PdfExport = () => { } }; + const handleJsonExport = () => { + try { + setIsExportingJson(true); + if (!activeResume) { + throw new Error("No active resume"); + } + + const jsonStr = JSON.stringify(activeResume, null, 2); + const blob = new Blob([jsonStr], { type: "application/json" }); + const url = window.URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = `${title}.json`; + link.click(); + + window.URL.revokeObjectURL(url); + toast.success(t("toast.jsonSuccess")); + } catch (error) { + console.error("JSON export error:", error); + toast.error(t("toast.jsonError")); + } finally { + setIsExportingJson(false); + } + }; + + const handlePrint = () => { + if (!printFrameRef.current) { + console.error("Print frame not found"); + return; + } + + const resumeContent = document.getElementById("resume-preview"); + if (!resumeContent) { + console.error("Resume content not found"); + return; + } + + const actualContent = resumeContent.parentElement; + if (!actualContent) { + console.error("Actual content not found"); + return; + } + + console.log("Found content:", actualContent); + + const pagePadding = globalSettings?.pagePadding; + const iframeWindow = printFrameRef.current.contentWindow; + if (!iframeWindow) { + console.error("IFrame window not found"); + return; + } + + try { + iframeWindow.document.open(); + const htmlContent = ` + + + + Print Resume + + + + + + + `; + + iframeWindow.document.write(htmlContent); + iframeWindow.document.close(); + + setTimeout(() => { + try { + iframeWindow.focus(); + iframeWindow.print(); + } catch (error) { + console.error("Error print:", error); + } + }, 1000); + } catch (error) { + console.error("Error setting up print:", error); + } + }; + + const isLoading = isExporting || isExportingJson; + const loadingText = isExporting + ? t("button.exporting") + : isExportingJson + ? t("button.exportingJson") + : ""; + return ( -
- -
+ <> + + + + + + + + {t("button.exportPdf")} + + + + {t("button.exportJson")} + + + + {t("button.print")} + + + +