ComponentOne PdfViewer for UWP
Key Features / Loading Documents from Application Resources
In This Topic
    Loading Documents from Application Resources
    In This Topic

    You can easily package an existing PDF file with your application and load it into C1PdfViewer at run time. For example, complete the following steps:

    1. Navigate to the Solution Explorer, right-click the project name, and select Add │ New Folder. Name the new folder "Resources".
    2. Right-click the Resources folder in the Solution Explorer and select Add │ Existing Item.
    3. In the Add Existing Item dialog box, locate a PDF file. In the file type drop-down box, you may need to select All Files to view the PDF file. Note that if you choose, you can instead pick another PDF file to use.
    4. In the Solution Explorer, click the PDF file you just added to the application (in this example, we'll assume the file is named MyPdf.pdf). In the Properties window, set its BuildAction property to Content and confirm that the Copy to Output Directory item is set to Do not Copy.
    5. Switch to Code view by double-clicking on the preview in Design view.
    6. Add the following imports statement to the top of the page:
    Visual Basic
    Copy Code
    Imports C1.Xaml.PdfViewer
    

    C#
    Copy Code
    using C1.Xaml.PdfViewer;
    
    1. Add the following code to the main class:
    Visual Basic
    Copy Code
    Dim resource As StorageFile = Await StorageFile.GetFileFromApplicationUriAsync(New Uri("ms-appx:///Resources/MyPdf.pdf"))
    Dim stream As Stream = Await resource.OpenStreamForReadAsync()
    Await PdfDocument.LoadFromFileAsync(resource)
    C1PdfViewer1.LoadDocument(stream)
    

    C#
    Copy Code
    StorageFile resource = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Resources/MyPdf.pdf"));
    Stream stream = await resource.OpenStreamForReadAsync();
    await PdfDocument.LoadFromFileAsync(resource);
    C1PdfViewer1.LoadDocument(stream);
    

    This code calls the LoadDocument method passing in the application resource stream.

    What You've Accomplished

    In this example you've loaded a PDF file into the C1PdfViewer from the application resources. You packaged an existing PDF file with your application in code and loaded it into the C1PdfViewer at run time.