How to increase speed of pdf rendering via PDF API? RRS feed

  • Question

  • I use FlipView to show pdf pages. I found PDF rendering is so slow when render each page.I written in C# only.
    (I follow sample: http://code.msdn.microsoft.com/windowsapps/PDF-viewer-sample-85a4bb30)

    I found this sample: http://msdn.microsoft.com/en-us/library/windows/apps/dn263107.aspx . Pdf rendering is so fast.
    But library in this sample written in C++. I try to adpat with my program , but i can't. it's difficult c++ for me.

    Please suggest me to adpat Pdf C++ library to have below feature:
    - Redering selected page.
    - Pdf size change when page changed (Now , the sample can't do it)
    - FlipView ItemsTemplate can be changed (one or two pages show)

    Thursday, April 3, 2014 6:41 AM

All replies

  • Did you modify the C# sample at all? If so, please post it here for us to review.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, April 3, 2014 12:20 PM
  • Here you are.


        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <FlipView x:Name="xFlipView">
                            <Image Source="{Binding Image}" HorizontalAlignment="Center" Height="{Binding Height}" Width="{Binding Width}"></Image>                      
                        <VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Horizontal" CleanUpVirtualizedItemEvent="VirtualizingStackPanel_CleanUpVirtualizedItemEvent" />


     public sealed partial class MainPage : Page
            ObservableCollection<FData> items = new ObservableCollection<FData>();
            public MainPage()
            protected override async void OnNavigatedTo(NavigationEventArgs e)
                StorageFolder installedLocation = Package.Current.InstalledLocation;
                var pdfFile = await installedLocation.GetFileAsync("Assets\\magazine.pdf");
                var pdfDocument = await PdfDocument.LoadFromFileAsync(pdfFile);
                for (int i = 0; i < pdfDocument.PageCount; i++)
                    items.Add(new FData() { PageNumber = i ,PdfDoc = pdfDocument ,Width = Window.Current.Bounds.Width,Height = Window.Current.Bounds.Height});
                xFlipView.ItemsSource = items;
            private void VirtualizingStackPanel_CleanUpVirtualizedItemEvent(object sender, CleanUpVirtualizedItemEventArgs e)
                var item = e.Value as FData;
        public class FData : INotifyPropertyChanged
            public int PageNumber { get; set; }
            public PdfDocument PdfDoc { get; set; }
            public double Height { get; set; }
            public double Width { get; set; }
            private ImageSource _image = null;
            public ImageSource Image 
                    if (_image == null)
                    return _image;
                    _image = value;
            private async void Rendering()
                using (var page = PdfDoc.GetPage((uint)PageNumber)) 
                    var renderOption = new PdfPageRenderOptions();
                    var img = new BitmapImage();
                    renderOption.DestinationHeight = (uint)(Height);              
                    InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();               
                    await page.RenderToStreamAsync(stream, renderOption);               
                    _image = img;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Image"));
                    _image = null;
            public event PropertyChangedEventHandler PropertyChanged;
            internal void Dispose()
                _image = null;

    Friday, April 4, 2014 2:33 AM