Implement Chromium-based PDF generation service; add fetchAndDownloadPdf utility and update contract generation endpoint
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user