Document Library for UWP
クイックスタート
PdfDocumentSource for UWP > クイックスタート

このクイックスタートでは、FlexViewer コントロールに PDF ファイルをロードする簡単なアプリケーションを作成する手順を説明します。ここでは、C1PdfDocumentSource 製品サンプルに含まれる DefaultDocument.pdf という PDF ファイルを使用します。

次の図に、FlexViewer にロードされた PDF ファイルを示します。

プログラムで FlexViewer に PDF ファイルをロードするには

手順 1:アプリケーションの設定

  1. 新しい UWP アプリケーションを作成します。
  2. C1FlexViewer コントロールをXAMLビューにドラッグアンドドロップします。

手順 2:FlexViewer への PDF ファイルのロード

  1. コードビューに切り替えて、次の名前空間を追加します。
    Imports C1.Xaml.Document
    Imports Windows.Storage
    
    using C1.Xaml.Document;
    using Windows.Storage;
    
  2. プロジェクトに PDF ファイルを追加します。この例では、製品サンプルにある DefaultDocument.pdf という PDF ファイルを使用します。
  3. 次のコードを追加して、StorageFile のインスタンスを作成し、C1PdfDocumentSourceの新しいインスタンスを初期化します。
    Dim pds As New C1PdfDocumentSource()
    Dim sf As StorageFile
    
    C1PdfDocumentSource pds = new C1PdfDocumentSource();
    StorageFile sf;
    
  4. 次のコードをMainPage()クラスコンストラクターに追加して、C1PdfDocumentSourceのインスタンスを作成します。そして、LoadFromFileAsyncメソッドを使用してPDFファイルをロードします。
    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. DocumentSource プロパティを使用して、FlexViewer コントロールでPDFファイルをレンダリングします。
    viewer.DocumentSource = pds
    
    viewer.DocumentSource = pds;
    

手順 3:プロジェクトのビルドおよび実行

  1. [Ctrl]+[Shift]+[B]キーを押してプロジェクトをビルドします。
  2. [F5]キーを押してアプリケーションを実行します。
関連トピック