Implement Chromium-based PDF generation service; add fetchAndDownloadPdf utility and update contract generation endpoint

This commit is contained in:
masoodafar-web
2025-11-14 15:20:46 +03:30
parent 230ba41113
commit 680ef3a7e2
9 changed files with 297 additions and 97 deletions
+25 -1
View File
@@ -35,7 +35,31 @@
<!-- Load MudBlazor JS before Blazor to avoid early JS interop calls failing; add cache-busting -->
<script src="_content/MudBlazor/MudBlazor.min.js" asp-append-version="true"></script>
<script src="_framework/blazor.server.js"></script>
<script src="/js/print-utils.js" asp-append-version="true"></script>
<script>
window.fetchAndDownloadPdf = async function(html, fileName){
try {
const res = await fetch('/contract/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ html: html, fileName: fileName })
});
if(!res.ok){
throw new Error('PDF generation failed: ' + res.status);
}
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = (fileName || 'contract') + '.pdf';
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(()=>URL.revokeObjectURL(url), 5000);
} catch(e){
console.error(e);
}
};
</script>
<script>
// elementId: id نوار (مثلاً "top")
// containerSelector: کانتینری که اسکرول می‌خوره؛ برای MudLayout معمولا ".mud-main-content"