Код: Выделить всё
JS Code:
document.addEventListener('DOMContentLoaded', function () {
renderDocx()
});
function renderDocx() {
let templateObjectId = @this.templateObjectId;
axios.get(`/template-objects/${templateObjectId}/personalize/preview`, {
responseType: 'arraybuffer'
}).then(response => {
let currentDocument = new Blob([response.data])
if (!currentDocument)
return;
docx.renderAsync(currentDocument, container)
.then((x) => {
renderThumbnails(container, document.querySelector("#document-container"));
console.log(x);
});
});
}
Personalize Preview Route code function:
public static function previewTemplate(TemplateObject $templateObject)
{
abort_if((! $templateObject->temporary_file_path || ! Storage::disk('local')->exists($templateObject->temporary_file_path)), Response::HTTP_NOT_FOUND);
// Get the file path
$path = Storage::disk('local')->path($templateObject->temporary_file_path);
// Serve the file with the headers
return response()->file($path, [
'Content-Type' => mime_content_type($path),
]);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... e-properly