Generating page preview for WordProcessing document

On this page

Starting from the version 23.5 the GroupDocs.Editor for .NET allows to generate a preview for arbitrary page in the loaded WordProcessing document, like DOC, DOCX, DOCM, RTF, ODT etc. The preview is generated in the SVG format, which is a vector graphics format and is supported in the numerous image viewers and also by any modern browser.

Using this feature the users can view and inspect any document of the imported WordProcessing document without actually editing it. This preview cannot be edited by the GroupDocs.Editor itself, it can be only obtained in SVG format and saved as usual - to the byte stream or file.

This feature is working regardless of the licensing mode of the GroupDocs.Editor for .NET: it works the same for both trial and licensed mode, there are no trial limitations for this feature. While generating the pages preview, the GroupDocs.Editor doesn’t write off the consumed bytes or credits.

With this feature was introduced, the GroupDocs.Editor for .NET finally supports generating a preview for all three major office format families: WordProcessing, Spreadsheet and Presentation.

For generating the pages preview for a particular WordProcessing document the user must perform the next steps:

The code sample below shows opening an unprotected WordProcessing DOCX file, obtaining a number of all pages inside this DOCX file, and then generating the previews for every page in a loop. Then these previews are saved to the disk. Please note that the GroupDocs.Editor is working in the trial mode, but page preview is generated for all the pages, and no trial copyright marks are present on these previews.

// Obtain a valid full path to the WordProcessing file
string inputPath = "SampleDoc.docx";

// Load WordProcessing file to the Editor constructor
using (GroupDocs.Editor.Editor editor = new Editor(inputPath))
{
	// Get document info for this file
	IDocumentInfo infoUncasted = editor.GetDocumentInfo(null);

	//Make sure it is really a WordProcessing of DOCX format
	Assert.AreEqual(Formats.WordProcessingFormats.Docx, infoUncasted.Format);

	// Cast this document info to the WordProcessingDocumentInfo type
	WordProcessingDocumentInfo infoWordProcessing = (WordProcessingDocumentInfo)infoUncasted;

	// Get the number of all pages
	int pagesCount = infoWordProcessing.PageCount;	

	//Iterate through all pages and generate the preview on every iteration
	for (int pageIndex = 0; pageIndex < pagesCount; pageIndex++)
	{
		// Generate one preview as SVG image by page index
		SvgImage oneSvgPreview = infoWordProcessing.GeneratePreview(pageIndex);

		// Save SVG preview to the file
		oneSvgPreview.Save(Path.Combine(outputFolder, oneSvgPreview.FilenameWithExtension));
	}
}

All WordProcessing formats are able to store the raster images. So when the specific page of some loaded document has one or more raster images, and for this page the SVG preview is generated, this/these raster image(s) will be embedded inside SVG in base64 format using the data URI scheme.

Concluding, the new page preview feature is by its essence a new public method in the existing WordProcessingDocumentInfo struct, that obtains a page index and returns an instance of SvgImage class. If the end-user needs to obtain a preview of the page in a raster format, but not in the vector, he can use the SaveToPng method in the SvgImage class — this method converts the SVG content of the current SvgImage to the PNG format and saves it to the specified System.IO.Stream.

On this page