0

I'm using laravel 9, vue 3 and phpoffice/phpword. I've also uploaded a word document which lives in my storage folder and that word document has stylings in it.

What I'm trying to do is display that word document in my vue page so that you can see it. So far I've only managed for the text to be displayed, but not any of the stylings.

Here is my FileService class

    public function scanDocxFile(File $file)
    {
        $file_path = $file->file_path . '/' . $file->filename;
        $phpWord = IOFactory::load($file_path);
        $htmlWriter = IOFactory::createWriter($phpWord, 'HTML');

        $htmlContent = '';
        ob_start();
        $htmlWriter->save('php://output');
        $htmlContent = ob_get_contents();
        ob_end_clean();
        return $htmlContent;
    }

This is my FileController

    public function getFile(File $file)
    {
        $file = fileService()->getSingleFile($file);

        return view('work.single-file', [
            'file' => $file
        ]);

    }

My blade file

@extends('adminlte::page')

@section('content')
    <div id="work-app">
        <single-file :file="{{ json_encode($file) }}"></single-file>
    </div>

@endsection

and my vue file

<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        {{ file }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: ['file'],
    components: {},
    data(){
        return {}
    },
    computed: {

    },
    methods: {

    },
    mounted() {
        console.log('Single File Component mounted.')
    }
}
</script>

<style scoped>

</style>
6
  • Can you not create a PDF and open it in Vue? What the current format of the file? Commented Jun 21, 2024 at 14:45
  • @kissu - it's a docx format Commented Jun 21, 2024 at 17:33
  • Not possible to convert it? Commented Jun 21, 2024 at 17:53
  • @kissu - I want to keep the docx format Commented Jun 25, 2024 at 7:34
  • Can you open such a format within a regular HTML page (without Vue)? Commented Jun 25, 2024 at 7:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.