Esempio n. 1
0
        private static async Task <string> RenderPage(Windows.Data.Pdf.PdfPage page, StorageFolder output)
        {
            var pagePath = string.Format("{0}.png", page.Index);
            var pageFile = await output.CreateFileAsync(pagePath, CreationCollisionOption.ReplaceExisting);

            using (var imageStream = await pageFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                PdfPageRenderOptions pdfPageRenderOptions = new PdfPageRenderOptions();
                pdfPageRenderOptions.IsIgnoringHighContrast = false;
                await page.RenderToStreamAsync(imageStream, pdfPageRenderOptions);

                await imageStream.FlushAsync();
            }

            return(output.Path.ToFolderPath() + pagePath);
        }
Esempio n. 2
0
        public async static Task <BitmapImage> BitmapImageFromPdf(Byte[] bytes)
        {
            Windows.Data.Pdf.PdfDocument pdfDocument;

            using (var stream = new MemoryStream(bytes))
            {
                pdfDocument = await Windows.Data.Pdf.PdfDocument.LoadFromStreamAsync(stream.AsRandomAccessStream());

                if (pdfDocument != null)
                {
                    // 1ページ目を読み込む
                    using (Windows.Data.Pdf.PdfPage page = pdfDocument.GetPage(0))
                    {
                        BitmapImage image = new BitmapImage();

                        using (var IMRAStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                        {
                            await page.RenderToStreamAsync(IMRAStream);

                            image.BeginInit();
                            image.CacheOption  = BitmapCacheOption.OnLoad;
                            image.StreamSource = IMRAStream.AsStream();
                            image.EndInit();
                        }

                        /*
                         * // save to file.
                         * JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                         * encoder.Frames.Add(BitmapFrame.Create(image));
                         *
                         * //string filePath = @"C:\Users\hoge\Desktop\test.jpg";
                         * using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create, FileAccess.Write))
                         * {
                         *  encoder.Save(fileStream);
                         * }
                         */
                        return(image);
                    }
                }
            }

            return(null);
        }
Esempio n. 3
0
 public PagePdf(pdf.PdfPage Page)
 {
     _Page = Page ?? throw new ArgumentNullException(nameof(Page));
 }
Esempio n. 4
0
 public PagePdf(pdf.PdfPage page)
 {
     Content = page;
 }