This topic describes how to perform operations on text documents, such as exporting them to PDF, retrieving page numbers, and jumping to specific pages.
This document is no longer maintained. Use the new version of Intelligent Media Management.
For more information about the differences between the new and old versions of Intelligent Media Management, see New and old version usage guide.
For more information about document preview in the new version of Intelligent Media Management, see WebOffice frontend development.
Export to PDF
/*
* Currently, only the RangeType and FrameSlides parameters are supported.
* @param: { Range?: WdExportRange, From?: number, To?: number, Item?: WdExportItem, IncludeDocProps?: bool }
* WdExportRange: {
* wdExportAllDocument: 0,
* wdExportCurrentPage: 2,
* wdExportFromTo: 3,
* wdExportSelection: 1,
* },
* WdExportItem: {
* wdExportDocumentContent: 0,
* wdExportDocumentWithMarkup: 7
* }
*/
await demo.WordApplication().ActiveDocument.ExportAsFixedFormat()Get page numbers and jump to pages
Define the variables used in the following examples.
const app = demo.WordApplication()
const {Enum} = appRetrieve the total number of pages
NoteBecause text documents use a stream-based layout, the total page count is available only after the entire document is loaded.
/* * @param: WdInformation: { * wdNumberOfPagesInDocument: 4 * } * @return: {PagesCount: number, End: boolean} */ let totalPages = await app.ActiveDocument.Range.Information(Enum.WdInformation.wdNumberOfPagesInDocument) if (totalPages.End) { console.log("Loading complete! Total pages:", totalPages.PagesCount) }Retrieve the current page number
/* * @param: WdInformation: { * wdActiveEndPageNumber: 3 * } * @return: number */ let currentPage = await app.ActiveDocument.Selection.Information(Enum.WdInformation.wdActiveEndPageNumber)Jump to a specific page
NoteBecause text documents use a stream-based layout, jumping to a page in a large document may take a long time. We recommend that you add a loading transition effect.
/* * @param: { What?: WdGoToItem, Which?: WdGoToDirection.wdGoToAbsolute, Count?: number, Name?: string} * WdGoToItem: { * wdGoToPage: 1, * } * WdGoToDirection: { * wdGoToAbsolute: 1 * } */ await app.ActiveDocument.Selection.GoTo(Enum.WdGoToItem.wdGoToPage, Enum.WdGoToDirection.wdGoToAbsolute, 10) // Or, use the following code. await app.ActiveDocument.Selection.GoTo({ What: Enum.WdGoToItem.wdGoToPage, Which: Enum.WdGoToDirection.wdGoToAbsolute, Count: 10 })Current page change event
function eventHandle() { // do something } // Listen for the current page change event. app.Sub.CurrentPageChange = eventHandle // Destroy the event listener. app.Sub.CurrentPageChange = null