如何在UWP应用程序中更改PDF文件的视图

如何在UWP应用程序中更改PDF文件的视图,pdf,uwp,uwp-xaml,pdfviewer,Pdf,Uwp,Uwp Xaml,Pdfviewer,我正在以图像形式打开PDF文件,并将其显示在flipview中 public async void OpenPDF(StorageFile file) { var pdfFile = await PdfDocument.LoadFromFileAsync(file); if (pdfFile == null) return; for (uint i = 0; i < pdfFile.Page

我正在以图像形式打开PDF文件,并将其显示在flipview中

public async void OpenPDF(StorageFile file)
    {        
        var pdfFile = await PdfDocument.LoadFromFileAsync(file);

        if (pdfFile == null)
            return;

        for (uint i = 0; i < pdfFile.PageCount; i++)
        {
            StorageFolder tempFolder = ApplicationData.Current.LocalFolder;
            StorageFile jpgFile = await tempFolder.CreateFileAsync(pdfFile + "-Page-" + i.ToString() + ".png", CreationCollisionOption.ReplaceExisting);
            var pdfPage = pdfFile.GetPage(i);

            if (jpgFile != null && pdfPage != null)
            {
                IRandomAccessStream randomStream = await jpgFile.OpenAsync(FileAccessMode.ReadWrite);
                await pdfPage.RenderToStreamAsync(randomStream);
                await randomStream.FlushAsync();
                randomStream.Dispose();
                pdfPage.Dispose();
            }

            PdfImages.Add(jpgFile.Path);
        }
        this.pdfViewer.ItemsSource = PdfImages;
    }
public异步void OpenPDF(存储文件)
{        
var pdfFile=await PdfDocument.LoadFromFileAsync(文件);
如果(Pdfile==null)
返回;
对于(uint i=0;i
我需要像windows 8.1 PDF viewer那样更改视图(FitWidth、FitPage、100%)


在Windows8.1应用程序中,我使用了Reader应用程序,它将并排打开PDF应用程序屏幕。但在UWP中,它的工作方式不同。所以我在寻找替代品。有很多PDF查看器可用,但都需要获得许可。那么是否有可用的免费源?

在UWP中,可以在控件中显示PDF文件内容,然后可以设置属性来描述如何拉伸图像以填充目标矩形。您还可以调整布局以根据需要显示PDF文件。有关显示PDF文件的更多详细信息,请查看示例

此外,这是一个简单的示例

MainPage.xaml


MainPage.xaml.cs

公共密封部分类主页面:第页
{
公共主页()
{
this.InitializeComponent();
PdfPages=新的ObservableCollection();
this.Loaded+=主页面_Loaded;
}
PDF文档PDF文档;
公共可观测收集PDF图像;
已加载专用异步void主页(对象发送方、路由目标)
{
var picker=new FileOpenPicker();
picker.FileTypeFilter.Add(“.pdf”);
var file=await picker.PickSingleFileAsync();
如果(文件!=null)
{
尝试
{
pdfDocument=等待pdfDocument.LoadFromFileAsync(文件);
}
捕获(例外情况除外)
{
Debug.WriteLine(例如消息);
}
}
如果(pdfDocument!=null)
{
uint pageCount=pdfDocument.pageCount;
对于(uint pageIndex=0;pageIndex
你好。是否可以在不使用.xaml的情况下显示此pdf,并且可以通过编程方式创建此pdf。。你能帮助我吗?。。