How to render single page in C1PdfViewer control

Posted by: hirenlad88 on 9 September 2017, 8:21 am EST

  • Posted 9 September 2017, 8:21 am EST

    Hi
    In my Application i have put two buttons like Next button and Previous button. and also put one C1PdfViewer control. Now i want to render only one page at a time. When i click on next or previous button at that time render page on viewer as per page index.
    I have already tried with bellow code.

     C1PdfViewer pdfviewer1;
    pdfviewer1=new C1PdfViewer();
    Assembly asm = typeof(MainPage).GetTypeInfo().Assembly;
    Stream stream = asm.GetManifestResourceStream("TestPDFViewer.1.pdf");
    pdfviewer1.LoadDocument(stream);

    IList<FrameworkElement> PageList = pdfviewer1.GetPages();


    In above code i don't understand how to render page from PageList variable. How to load one single page in C1PdfViewer using FrameworkElement ?
    Do you have any examples regarding to GetPages() method. Please to suggest to me for fulfilling my application requirement.

    Thanks & Regards
    HireN Lad.
  • Replied 9 September 2017, 8:21 am EST

    Hello HireN,

    One way to display 1 page at a time is to load the pages into a FlipView control.

    <FlipView x:Name="flipview1" Background="White" />


    flipview1.ItemsSource = PageList;


    If you want to programmatically just get one page you can do it by index.

    pdfviewer1.GetPages()[x];
  • Replied 9 September 2017, 8:21 am EST

    Hi Greg,

    Thanks for your reply. But i don't want to load my single page in any panel or FlipView. i want to display my page in pdfviewer only. If i ll used pdfviewer at run time and load pdf in memory and get pages from pdfviewer. As we know GerPages() method return Framework Elements, So my question is can i have load framework element in another pdfviewer which is appear at design time. Is it possible ?

    Regards
    HireN Lad.
  • Replied 9 September 2017, 8:21 am EST

    So to help me better understand, you want to display one specific page (let's say page #5) of a larger (let's say 10 page) document? do you want the user to be able to navigate to page 6? Do you want text search and zoom functionality?

    Perhaps you don't need to use PdfViewer to display the page, but just to load the document.

    Also we have plans to support our C1Pdf library that creates PDf documents on the fly. The current Silverlight/WPF version can render FrameworkElements to PDF which would do what you want, if we get it fully supported in WinRT. The current ETA is mid-March for this library.

    Regards,
  • Replied 9 September 2017, 8:21 am EST

    Hi Greg,
    Yes i want to display(load) one specific page in viewer with navigation and zooming functionality. Can i have get one sample application about how to use C1PdfPageContext, C1PdfDocument and C1PdfViewer.

    Thanks and Regards
    HireN Lad.
  • Replied 9 September 2017, 8:21 am EST

    Hi, unfortunately there is no way to work with C1PdfPageContext and C1PdfDocument which are internal classes used in C1PdfViewer.

    You can load one specific page with the GoToPage method. Use it inside the Async Completed event of the LoadDocumentAsync method. This way you can display 1 page with navigation and zooming.


    // Load file in asynchronous way
    IAsyncAction load = pdfViewer.LoadDocumentAsync(stream);
    load.Completed += new AsyncActionCompletedHandler(Completed);

    private async void Completed(IAsyncAction a, AsyncStatus s)
    {
    pdfViewer.GoToPage(5);
    }
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels