Esempio n. 1
0
        /// <summary>
        /// Load pdf page except pdf source.it only render the page bound.
        /// </summary>
        /// <param name="pdfDoc"></param>
        void LoadPagesWithoutSource(PdfDocument pdfDoc)
        {
            double pageOffset = 0;

            for (uint i = 0; i < pdfDoc.PageCount; i++)
            {
                using (var page = pdfDoc.GetPage(i))
                {
                    var zoomRate = this.ActualWidth / page.Size.Width;

                    var pdfProvider = new PdfProvider
                    {
                        Bound = new Bound
                        {
                            Width          = this.ActualWidth,
                            Height         = page.Size.Height * zoomRate,
                            VerticalOffset = pageOffset
                        },
                        Index = (int)i
                    };

                    PdfPages.Add(pdfProvider);
                    pageOffset += pdfProvider.Bound.Height;
                }
            }
        }
        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)
            {
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
 /// <summary>
 /// Allows adding of BitmapImage objects to the control without a Pdf Document, so the
 /// control can act as an image viewer as well as a Pdf Document viewer.
 /// </summary>
 /// <param name="img"></param>
 public void AddPdfImage(BitmapImage img)
 {
     if (null != img)
     {
         PdfPages.Add(img);
         _lastPdfImageLoaded++;
     }
 }
 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);
 }
Esempio n. 6
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);
            }
        }