ComponentOne PdfViewer for WPF and Silverlight
PdfViewer for WPF and Silverlight Overview / Getting Started / Quick Start / Step 2: Adding PDF Content to the Application
In This Topic
    Step 2: Adding PDF Content to the Application
    In This Topic

    In the previous step, you created a WPF or Silverlight application and added the C1PdfViewer control to your project. In this step, you add PDF content to the application. You can use a PDF file of your choice to be viewed in the PdfViewer control. The code example given below uses C1XapOptimize.pdf file, which is by default located in the pre-installed folder at the given location.

    C:\Users\...\Documents\ComponentOne Samples\WPF\C1.WPF.PdfViewer\CS\PdfViewerSamples

     

    Complete the following steps to add the sample PDF file to your application, and loading the same in the PdfViewer control at runtime.

    1. In the Solution Explorer, right-click your project and choose Add │ Existing Item.
    2. In the Add Existing Item dialog box, browse the C1XapOptimizer.pdf file kept at the above location and click OK.
      You can also add another PDF file of your choice to be viewed at runtime.
    3. In the Solution Explorer, right-click the PDF file that you added and set its BuildAction attribute to Resource and Copy to Output Directory attribute to Do not Copy.
    4. Switch to code view and add the following import statements.
      Imports C1.WPF.PdfViewer
      
      using C1.WPF.PdfViewer;
      

      For Silverlight, use the following import statements:

      Visual Basic - Imports C1.Silverlight.PdfViewer

      C# - using C1.Silverlight.PdfViewer

    5. Add the given code to load the added PDF file into PdfViewer control.
      Public Sub New()
          InitializeComponent()
          Dim resource = Application.GetResourceStream(New Uri("PDFViewerQuickStartVB;component/C1XapOptimizer.pdf", UriKind.Relative))
      
          Me.C1PdfViewer1.LoadDocument(resource.Stream)
      End Sub
      
      public MainWindow()
      {
          InitializeComponent();
          var resource = Application.GetResourceStream(new Uri("PDFViewer_QuickStart;component/C1XapOptimizer.pdf", UriKind.Relative));
      
          this.C1PdfViewer1.LoadDocument(resource.Stream);
      
      }
      

    The above code first loads the sample PDF file in a stream, and then loads the stream into the PDFViewer control. Note that if your application and PDF file are named differently, then you need to specify these names in the code.