Document Library for UWP | ComponentOne
PdfDocumentSource for UWP / Quick Start
In This Topic
    Quick Start
    In This Topic

    This quick start topic guides you through a step-by-step process of creating a simple application for loading a PDF file in the FlexViewer control. It uses a PDF file named DefaultDocument.pdf, taken from the C1PdfDocumentSource product sample.

    The following image shows a PDF file loaded in FlexViewer.

    To load a PDF file in FlexViewer programmatically

    Step 1: Setting up the application

    1. Create a new UWP application.
    2. Drag and drop C1FlexViewer control in the XAML view.

    Step 2: Load the PDF file in FlexViewer

    1. Switch to the code view and add the following namespace.
      Imports C1.Xaml.Document
      Imports Windows.Storage
      
      using C1.Xaml.Document;
      using Windows.Storage;
      
    2. Add a PDF file to the project. In our case, we have used PDF file named DefaultDocument.pdf from the product sample.
    3. Add the following code to create an instance of StorageFile and initialize a new instance of C1PdfDocumentSource.
      Dim pds As New C1PdfDocumentSource()
      Dim sf As StorageFile
      
      C1PdfDocumentSource pds = new C1PdfDocumentSource();
      StorageFile sf;
      
    4. Add the following code in the MainPage() class constructor to create an instance of C1PdfDocumentSource and load the PDF file using LoadFromFileAsync method.
      Dim fileName As String = Nothing
      
      sf = Await StorageFile.GetFileFromApplicationUriAsync(New Uri _
               ("ms-appx:///DefaultDocument.pdf"))
      Await pds.LoadFromFileAsync(sf)
      fileName = Path.GetFileName(sf.Name)
      
      string fileName = null;
      
      sf = await StorageFile.GetFileFromApplicationUriAsync(
           new Uri("ms-appx:///DefaultDocument.pdf"));
      await pds.LoadFromFileAsync(sf);
      fileName = Path.GetFileName(sf.Name);
      
    5. Render the PDF file in the FlexViewer control using DocumentSource property.
      viewer.DocumentSource = pds
      
      viewer.DocumentSource = pds;
      

    Step 3: Build and run the project

    1. Press Ctrl+Shift+B to build the project.
    2. Press F5 to run the application.
    See Also