Search results

Scrolling

The Document editor renders the document as page by page. You can scroll through the pages by mouse wheel or touch interactions. You can also scroll through the page by using ‘scrollToPage()’ method of document editor instance. Refer to the following code example.

Source
Preview
app.vue
<template>
    <div id="app">
        <ejs-documenteditor ref="documenteditor" style="width: 100%;height: 100%;"></ejs-documenteditor>
    </div>
</template>
<script>
import Vue from 'vue'
import { DocumentEditorPlugin } from '@syncfusion/ej2-vue-documenteditor';

Vue.use(DocumentEditorPlugin);

export default {
    data: function() {
        return {
        };
    },
    mounted: function() {
            let defaultDocument: object = {
            "sections": [
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "First page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                },
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "Second page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                }
            ],
            "characterFormat": {},
            "paragraphFormat": {},
            "background": {
                "color": "#FFFFFFFF"
            },
            "styles": [
                {
                    "type": "Paragraph",
                    "name": "Normal",
                    "next": "Normal"
                },
                {
                    "type": "Character",
                    "name": "Default Paragraph Font"
                }
            ]
        }
        this.$refs.documenteditor.open(JSON.stringify(defaultDocument));
        this.$refs.documenteditor.scrollToPage(2);
    }
}
</script>
<style>
 @import "../../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";
</style>


{% endraw %}

Calling this method brings the specified page into view but doesn’t move selection. Hence this method will work by default. That is, it works even if selection is not enabled.

In case, if you wish to move the selection to any page in document editor and bring it into view, you can use ‘goToPage()’ method of selection instance. Refer to the following code example.

Source
Preview
app.vue
<template>
    <div id="app">
        <ejs-documenteditor ref="documenteditor" :enableSelection='true' :isReadOnly=false style="width: 100%;height: 100%;"></ejs-documenteditor>
    </div>
</template>
<script>
import Vue from 'vue'
import { DocumentEditorPlugin, Selection } from '@syncfusion/ej2-vue-documenteditor';

Vue.use(DocumentEditorPlugin);

export default {
    data: function() {
        return {
        };
    },
    provide: {
        DocumentEditor : [Selection]
    },
    mounted: function() {
        let defaultDocument: object = {
            "sections": [
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "First page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                },
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "Second page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                },
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "Third page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                }
            ],
            "characterFormat": {},
            "paragraphFormat": {},
            "background": {
                "color": "#FFFFFFFF"
            },
            "styles": [
                {
                    "type": "Paragraph",
                    "name": "Normal",
                    "next": "Normal"
                },
                {
                    "type": "Character",
                    "name": "Default Paragraph Font"
                }
            ]
        }
        this.$refs.documenteditor.open(JSON.stringify(defaultDocument));
        this.$refs.documenteditor.ej2Instances.selection.goToPage(3);
    }
}
</script>
<style>
 @import "../../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";
</style>


{% endraw %}

Zooming

You can scale the contents in document editor ranging from 10% to 500% of the actual size. You can achieve this using mouse or touch interactions. You can also use ‘zoomFactor’ property of document editor instance. The value can be specified in a range from 0.1 to 5. Refer to the following code example.

<template>
    <div id="app">
        <ejs-documenteditor ref="documenteditor" style="width: 100%;height: 100%;"></ejs-documenteditor>
    </div>
</template>
<script>
import Vue from 'vue'
import { DocumentEditorPlugin } from '@syncfusion/ej2-vue-documenteditor';

Vue.use(DocumentEditorPlugin);

export default {
    data: function() {
        return {
        };
    },
    mounted: function() {
        this.$refs.documenteditor.zoomFactor = 3;
    }
}
</script>
<style>
 @import "../../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";
</style>

Page Fit Type

Apart from specifying the zoom factor as value, the Document editor provides option to specify page fit options such as fit to full page or fit to page width. You can set this option using ‘fitPage’ method of document editor instance. Refer to the following code example.

<template>
    <div id="app">
        <ejs-documenteditor ref="documenteditor" style="width: 100%;height: 100%;"></ejs-documenteditor>
    </div>
</template>
<script>
import Vue from 'vue'
import { DocumentEditorPlugin } from '@syncfusion/ej2-vue-documenteditor';

Vue.use(DocumentEditorPlugin);

export default {
    data: function() {
        return {
        };
    },
    mounted: function() {
        this.$refs.documenteditor.fitPage('Fit page width');
    }
}
</script>
<style>
 @import "../../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";
</style>

Zoom option using UI

The following code example shows how to provide zoom options in document editor.

Source
Preview
app.vue
<template>
    <div id="app">
        <ejs-documenteditor ref="documenteditor" v-bind:selectionChange='onSelectionChange' v-bind:viewChange='onViewChange' v-bind:documentChange='onDocumentChange' :enableSelection='true' :isReadOnly=false style="width: 100%;height: 100%;"></ejs-documenteditor>
        <div id="documenteditor_statusbar">
            <label style="margin-top: 6px;margin-right: 2px">Page </label>
            <div class="single-line e-de-pagenumber-text" v-on:keydown='pageKeydownEvent' v-on:click='pagerClickEvent' id="editablePageNumber" style="font-size:12px;font-weight: 700;display: inline-flex;height: 17px;padding: 0px 4px;" contenteditable="false">
                <label id="documenteditor_page_no" style="text-transform:capitalize;white-space:pre;overflow:hidden;user-select:none;cursor:text;height:17px;max-width:150px">{{currentPage}}</label>
            </div>
            <label id="documenteditor_pagecount_separator" style="margin-left:2px;letter-spacing: 1.05px">of</label>
            <label id="documenteditor_pagecount" style="margin-left:6px;letter-spacing: 1.05px">{{pageCount}}</label>
            <ejs-dropdownbutton ref="de_zoom" :items="zoomItems" class="e-de-statusbar-zoom" :content="zoomContent" v-bind:select="onZoom" title="Zoom level. Click or tap to open the Zoom options."></ejs-dropdownbutton>
        </div>
    </div>
</template>
<script>
import Vue from 'vue'
import { DocumentEditorPlugin, Selection } from '@syncfusion/ej2-vue-documenteditor';
import { DropDownButtonPlugin } from '@syncfusion/ej2-vue-splitbuttons';

Vue.use(DocumentEditorPlugin);
Vue.use(DropDownButtonPlugin);

export default {
    props: ['pageCount', 'currentPage', 'zoomContent'],
    data: function() {
        return {
            zoomContent: "100%",
            zoomItems: [
            {
                text: '150%',
            },
            {
                text: '125%',
            },
            {
                text: '100%',
            },
            {
                text: '75%',
            },
            {
                text: '50%',
            },
            {
                separator: true
            },
            {
                text: 'Fit one page'
            },
            {
                text: 'Fit page width',
            }],
            pageCount: 1,
            currentPage: 1
        };
    },
    provide: {
        DocumentEditor : [Selection]
    },
    methods :{
         onViewChange: function(args) {
             this.currentPage =  args.startPage;
         },
         onSelectionChange : function(args) {
            this.currentPage =  this.$refs.documenteditor.ej2Instances.selection.startPage;
         }
         onDocumentChange: function() {
           this.pageCount =  this.$refs.documenteditor.ej2Instances.pageCount
           this.zoomContent = Math.round(this.$refs.documenteditor.ej2Instances.zoomFactor * 100) + '%';
         },
         onZoom: function (args) {
            let zoomValue = args.item.text;
            if (zoomValue.match('Fit one page')) {
                this.$refs.documenteditor.ej2Instances.fitPage('FitOnePage');
            } else if (zoomValue.match('Fit page width')) {
                this.$refs.documenteditor.ej2Instances.fitPage('FitPageWidth');
            } else {
                this.$refs.documenteditor.ej2Instances.zoomFactor = parseInt(zoomValue, 0) / 100;
            }
            this.zoomContent = Math.round(this.$refs.documenteditor.ej2Instances.zoomFactor * 100) + '%';
        },
        pageKeydownEvent: function (e) {
            if (e.which === 13) {
                e.preventDefault();
                let pageNumber = parseInt(document.getElementById("editablePageNumber").textContent, 0);
                if (pageNumber > this.$refs.documenteditor.ej2Instances.pageCount) {
                    this.updatePageNumber();
                } else {
                    this.$refs.documenteditor.ej2Instances.selection.goToPage(parseInt(document.getElementById("editablePageNumber").textContent, 0));
                }
                document.getElementById("editablePageNumber").contentEditable = 'false';
                if (document.getElementById("editablePageNumber").textContent === '') {
                    this.updatePageNumber();
                }
            }
            if (e.which > 64) {
                e.preventDefault();
            }
        },
        pageBlurEvent: function () {
            if (document.getElementById("editablePageNumber").textContent === '' || parseInt(document.getElementById("editablePageNumber").textContent, 0) > this.$refs.documenteditor.ej2Instances.pageCountt) {
                this.updatePageNumber();
            }
            document.getElementById("editablePageNumber").contentEditable = 'false';
        },
        pagerClickEvent: function () {
            document.getElementById("editablePageNumber").contentEditable = 'true';
            document.getElementById("editablePageNumber").focus();
            window.getSelection().selectAllChildren(document.getElementById("editablePageNumber"));
        },
        updatePageNumber: function () {
            this.currentPage = this.$refs.documenteditor.ej2Instances.selection.startPage.toString();
        }
    },
    mounted: function() {
        let defaultDocument: object = {
            "sections": [
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "First page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                },
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "Second page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                },
                {
                    "blocks": [
                        {
                            "paragraphFormat": {
                                "styleName": "Normal"
                            },
                            "inlines": [
                                {
                                    "text": "Third page"
                                }
                            ]
                        }
                    ],
                    "headersFooters": {},
                }
            ],
            "characterFormat": {},
            "paragraphFormat": {},
            "background": {
                "color": "#FFFFFFFF"
            },
            "styles": [
                {
                    "type": "Paragraph",
                    "name": "Normal",
                    "next": "Normal"
                },
                {
                    "type": "Character",
                    "name": "Default Paragraph Font"
                }
            ]
        }
        this.$refs.documenteditor.open(JSON.stringify(defaultDocument));
        document.getElementById('editablePageNumber').addEventListener('blur',this.pageBlurEvent);
    }
}
</script>
<style>
 @import "../../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";

 .single-line {
    cursor: text !important;
    outline: none;
}

.single-line:hover {
    border-color: #e4e4e4 !important;
}

[contenteditable="true"].single-line {
    white-space: nowrap;
    border-color: #e4e4e4 !important;
}

.e-de-pagenumber-text:hover {
    background-color: #f4f4f4 !important;
}

[contenteditable="true"].single-line * {
    white-space: nowrap;
}

.e-de-statusbar-zoom {
    float: right;
    text-align: center;
    padding: 2px;
    line-height: 19px;
    margin-top: 1px;
}
</style>


{% endraw %}