3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Power Apps で SharePoint ドキュメントライブラリの pdf ファイルを表示する

Last updated at Posted at 2025-01-10

はじめに

SharePoint ドキュメントライブラリ内の pdf ファイルを Power Apps 上で表示したいというニーズがありますが、少し癖があるので備忘のため記事化しておきます。

image.png

アプローチ

こんな感じでドキュメントライブラリ内の pdf ファイルを Power Apps の PDF ビューアーで表示させます。

image.png

まず、左側のギャラリーで選択したアイテムのプロパティを PDF ビューアーの[Document]プロパティに入れればいいと思いましたが、残念ながら上手くいきませんでした。[代わりにブラウザーで開く] をクリックするとアクセスできますが。。

image.png

最終的には、Power Automate と連携するこどで実現できました。

Power Apps トリガーのため、こちらから新規作成します。

image.png

image.png

image.png

Power Automate の作りはシンプルです。こんな感じでファイルの識別子を Power Apps から受け取り、そちらを基にファイルコンテンツを取得して、変換をして Power Apps に返します。

image.png

技術的にコアとなる [作成] アクションの式は以下の通りです。アクション名が既定のままであれば、そのまま貼り付け可能です。

image.png

dataUri(base64ToBinary(body('ファイル_コンテンツの取得')?['$content']))

そして、作成アクションの出力を Power Apps に返します。

image.png

こちらの Power Automate と Power Apps をつなぎ、例えば、以下のように、ギャラリー内に追加した pdf のアイコンをクリックした際 ([OnSelect]プロパティ)、Power Automate のフローを渡して、結果を変数に格納します。

image.png

Set(
    varDocumentContent,
    GetPDFContents.Run(Gallery1.Selected.識別子).result
)

そして、PDF ビューアーの[Document]プロパティに変数を入れいます。こちらで、Power Apps の PDF ビューアーで、SharePoint ドキュメントライブラリ内の pdf ファイルを閲覧できるようになりました。

image.png

image.png

※Power Apps だけでも実現する方法はありそうですが、少し癖があるため、こちらの方法の方が、再現性が高いと考えています。もちろん、将来的には、例えば「ギャラリー名.Selected.プロパティ名」だけで表示できるようになるなど、もっと簡単に実現できるようになることを期待しています

なお、ギャラリー内の PDF アイコンについて、以下のようにして、ファイルの拡張子が pdf の場合だけ表示するようにしています。

image.png

If(
    EndsWith(
        ThisItem.拡張子付きのファイル名,
        "pdf"
    ),
    true,
    false
)
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?