Beispiel #1
0
        /// <summary>
        /// 获得PDF文件的预览图
        /// </summary>
        /// <param name="path">文档路径</param>
        /// <returns>PDF的预览</returns>
        public static async Task <IRandomAccessStream> GetPDFPreviewAsync(string path, uint p = 0)
        {
            StorageFile pdfFile;

            try
            {
                pdfFile = await StorageFile.GetFileFromPathAsync(path);

                var pdf = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(pdfFile);

                var page = pdf.GetPage(p);
                currentPdfCount = pdf.PageCount;
                currentPdfPage  = p;
                currentPdfPath  = path;
                InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
                await page.RenderToStreamAsync(ms);

                currentFileType = PreviewModel.FileType.Pdf;
                return(ms);
            }
            catch (Exception)
            {
                return(await GetPicPreviewAsync(defaultPicPath));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获得图片文件的预览图
        /// </summary>
        /// <param name="path">图片路径</param>
        /// <returns>图片的预览</returns>
        public static async Task <IRandomAccessStream> GetPicPreviewAsync(string path, bool inner = false)
        {
            {
                StorageFile file;
                if (inner == false)
                {
                    file = await StorageFile.GetFileFromPathAsync(path);
                }
                else
                {
                    file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(path));
                }
                var res = await file.OpenAsync(FileAccessMode.Read);

                currentFileType = PreviewModel.FileType.Picture;
                return(res);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获得Word文件的预览图
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <returns>Word的预览</returns>
        public static async Task <IRandomAccessStream> GetWordPreviewAsync(string path)
        {
            StorageFile file = await StorageFile.GetFileFromPathAsync(path);

            var res = await file.OpenAsync(FileAccessMode.Read);

            WordDocument wordDocument = new WordDocument();

            wordDocument.Open(res.AsStream(), Syncfusion.DocIO.FormatType.Automatic);
            DocIORenderer render = new DocIORenderer();

            Syncfusion.Pdf.PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
            render.Dispose();
            wordDocument.Dispose();
            InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();

            pdfDocument.Save(ms.AsStream());
            currentFileType = PreviewModel.FileType.Office;
            return(await GetPDFPreviewFromStreamAsync(ms));
        }