async void Load(PdfDocument pdfDoc)
        {
            try
            {
                PdfPages.Clear();

                for (uint i = 0; i < pdfDoc.PageCount; i++)
                {
                    BitmapImage image = new BitmapImage();

                    var page = pdfDoc.GetPage(i);

                    using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                    {
                        await page.RenderToStreamAsync(stream);

                        await image.SetSourceAsync(stream);
                    }

                    PdfPages.Add(image);
                }
                pdfviewer.ItemsSource = PdfPages;
            }

            catch (Exception)
            {
            }
        }
Пример #2
0
        private async void Button_TappedAsync(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            if (PdfPages.Count == 0)
            {
                //load the pdf
                StorageFile f = await
                                StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/PrivacyPolicy.pdf"));

                PdfDocument doc = await PdfDocument.LoadFromFileAsync(f);

                PdfPages.Clear();

                for (uint i = 0; i < doc.PageCount; i++)
                {
                    BitmapImage image = new BitmapImage();

                    var page = doc.GetPage(i);

                    using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                    {
                        await page.RenderToStreamAsync(stream);

                        await image.SetSourceAsync(stream);
                    }

                    PdfPages.Add(image);
                }
                scroll.Height = Window.Current.Bounds.Height;
                scroll.Width  = Window.Current.Bounds.Width;
                scroll.ChangeView(null, null, (float)((Window.Current.Bounds.Width) / PdfPages[0].PixelWidth));
                pop.ItemsSource = PdfPages;
            }
            PopUp.IsOpen = true;
        }
Пример #3
0
 /// <summary>
 /// Clear PdfPages, set sources to null, clear counters.
 /// </summary>
 public void ClearPdfImages()
 {
     // clear it out
     PdfPages.Clear();
     PageCount           = 0;
     _lastPdfImageLoaded = 0;
     Source            = null;
     StorageFileSource = null;
 }
Пример #4
0
 public void Dispose()
 {
     PdfPages.Clear();
     PdfPages = null;
     resizeTimer.Stop();
     resizeTimer.Tick             -= resizeTimer_Tick;
     resizeTimer                   = null;
     svPdfContainer.ScrollChanged -= svPdfContainer_ScrollChanged;
 }
 private async void CreatePages(PdfDocument imageDoc)
 {
     PdfPages.Clear();
     for (int i = 0; i < imageDoc.PageCount; i++)
     {
         PdfPages.Add(new PdfViewerPage());
     }
     _pageCache = new PageCacheManager(PdfPages, imageDoc)
     {
         Prefetch = BufferPageCount
     };
     await _pageCache.LoadSelectedPage(Carousel.SelectedIndex);
 }
 public async Task LoadAsync()
 {
     if (Source == null)
     {
         PdfPages.Clear();
     }
     else
     {
         if (Source.IsFile || !IsWebUri(Source))
         {
             await LoadFromLocalAsync();
         }
         else if (IsWebUri(Source))
         {
             await LoadFromRemoteAsync();
         }
         else
         {
             throw new ArgumentException($"Source '{Source.ToString()}' could not be recognized!");
         }
     }
 }
Пример #7
0
        //A method to Load in the Remote PDF file
        async void Load(Windows.Data.Pdf.PdfDocument pdfDoc)
        {
            PdfPages.Clear();
            //set up the pdf by saying i is less than total no. pages
            for (uint i = 0; i < pdfDoc.PageCount; i++)
            {
                //Set up a new image to render the pdf to the app
                BitmapImage image = new BitmapImage();

                //get i-the pdf doc
                var page = pdfDoc.GetPage(i);

                //Ref:docs.Microsoft.com
                //Provides random access of data in input and output streams
                //that are stored in memory instead of on disk.
                using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                {
                    await page.RenderToStreamAsync(stream);

                    await image.SetSourceAsync(stream);
                }
                PdfPages.Add(image);
            }
        }