Hello,
Is it possible to convert Xps to html or image using Words?
And one thing not clear, Words open chm files, which are a collection of different html help pages.
After loading it, and saving as Tiff for example, which html page of the source chm will be used?
@australian.dev.nerds, Aspose.Words supports XPS only as an output format. You can render XPS to image using the following code:
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Xps.Packaging;
using System.IO;
using System;
FixedDocumentSequence docSequence;
using (XpsDocument xpsDoc = new XpsDocument(inputFileName, FileAccess.Read))
{
docSequence = xpsDoc.GetFixedDocumentSequence();
}
if(docSequence == null)
throw new Exception("Cannot get DocumentSequence from the document. Please make sure the input file is a valid XPS document.");
// Now we can render the specified page.
DocumentPaginator paginator = docSequence.DocumentPaginator;
if(pageIndex >= paginator.PageCount)
throw new ArgumentOutOfRangeException("pageIndex", "Specified page index is out of range.");
FrameworkElement fe = (FrameworkElement)paginator.GetPage(pageIndex).Visual;
RenderTargetBitmap bmp = new RenderTargetBitmap((int)fe.ActualWidth, (int)fe.ActualHeight, 96d, 96d, PixelFormats.Default);
bmp.Render(fe);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
using (Stream stream = File.Create(outputFileName))
{
png.Save(stream);
}
Please refer to .NET Framework documentation for more details:
1 Like
@australian.dev.nerds TIFF is a multipage image format. All pages will be saved to TIFF image by default. If you save to image formats like PNG or JPEG then only first page will be saved. You could control which page to save with ImageSaveOptions.PageSet property.