2015-02-09 145 views

回答

0

Windows phone 8.1 webview不支持原生pdf渲染。 你可以看看Mozill pdfJS。希望能帮助到你。

-1

我不确定关于WebView,但是您可以在应用程序中原生呈现PDF。

您可以创建一个流式文件,并将该文件提供给Windows.Data.PDF提供的PDF渲染器。它工作得很好。检查我的帖子here进行了详细的教程

public PdfDocument Document { get; set; } 
public PdfPage CurrentPage { get; set; } 

创建流文件 -

try 
{                   
    IRandomAccessStreamReference thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(webURL)); 
    StorageFile file1 = await StorageFile.CreateStreamedFileFromUriAsync("temp.pdf", new Uri(webURL), thumbnail); 
    this.Document = await PdfDocument.LoadFromFileAsync(file1) 
} 
catch (Exception ex) 
{ 
    MessageDialog dialog = new MessageDialog(ex.Message); 
    dialog.ShowAsync(); 
    return; 
} 
for (int i = 0; i < Document.PageCount; i++) 
{ 
    await this.RenderPage(i); 
} 

渲染网页 - WP8下

private async Task RenderPage(int index) 
{ 
    this.CurrentPage = this.Document.GetPage((uint)index); 
    using (IRandomAccessStream stream = new MemoryStream().AsRandomAccessStream()) 
    { 
     await this.CurrentPage.RenderToStreamAsync(stream); 
     BitmapImage source = new BitmapImage(); 
     source.SetSource(stream); 
     Image i = new Image(); 
     i.Source = source; 
     i.Margin = new Thickness(0,5,0,0); 
     PagePanel.Children.Add(i); 
    } 
} 
+2

'Windows.Data.Pdf'命名空间不可用。 1 – zepar 2016-02-18 15:12:26