Power Apps:预览SharePoint文档库的PDF文档
Power Apps 提供了 PDF Viewer 控件,可以在应用中预览 PDF 文件。但该控件有一个限制:
- 只能显示 直接的 PDF 链接(HTTPS、可匿名访问、不可跳转)。
- 如果链接需要身份验证(如 SharePoint 默认情况),会报错 “Couldn’t open PDF file” 并提示在浏览器中打开。
因此,无法直接在 Power Apps 内嵌预览 SharePoint 文件,除非管理员将文档库设置为允许匿名访问(通常不符合企业安全策略)。

无法直接浏览,可以用 Power Automate 取文件内容(字节流),返回给 Power Apps,Power Apps 再把它绑定到 PDF Viewer 的Document属性
实施步骤
添加组件
- 左侧:插入 Gallery,
Items属性绑定 SharePoint 文档库。 - 右侧:插入 PDF Viewer 控件,设置:
ShowControls = trueDocument = varPdfDoc(后续通过变量赋值)

创建 Power Automate流程
- 触发器:Power Apps,需要获取文件的标识符

- 动作 1:SharePoint → 获取文件内容

- 动作 2:内容转换,使用组件将内容转换成BASE64编码

- 动作 3:添加 Respond to a PowerApp or flow 动作:
- 点击 + 添加输出 → 选择 Text。
- 输出名称:
- 值:选择上一步 Compose 的 Outputs(或在 fx 中输入
outputs('Compose'))。
关键点:不要在输出名称里直接写表达式,只能在值里使用表达式。

- 保存后,回到 Power Apps,数据窗格中添加该 Flow。
为变量赋值
在Gallery中的Onselect编辑
Select(Parent);
// 假设 Flow 名为 'GetPDFContent'
// 1) 调用 Flow,取到 Text(Base64)
Set(varPdfBytes,GetPDFContent.Run(// 传入文件标识符,例如:ThisItem.标识符 )
);// 2) 拼接数据 URI(字符串)
Set(varPdfDoc,"data:application/pdf;base64," & varPdfBytes.z
);
当用户在 Gallery 中选择文档时,右侧 PDF Viewer 即可预览该 PDF 文件。

