Pdf in Windows Phone 8.1

本文关键字:Phone Windows in Pdf | 更新日期: 2023-09-27 18:22:08

因为PdfDocument类只在Windows 8.1中可用,所以在Windows phone 8.1(Windows运行时)中有什么东西可以用来在我的应用程序中渲染pdf文件?

编辑

MuPdf工作很棒!但为了让它在Windows Phone项目中发挥作用,我不得不手动编辑.csproj

我不得不添加这个代码:

<Reference Include="MuPDFWinRT, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL" Condition="'$(Platform)'=='x86'">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..'MuPDF'x86'MuPDFWinRT.winmd</HintPath>
</Reference>
<Reference Include="MuPDFWinRT, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL" Condition="'$(Platform)'=='ARM' ">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..'MuPDF'ARM'MuPDFWinRT.winmd</HintPath>
</Reference>

这是一个使用示例:

IBuffer readBuffer = pdf.AsBuffer();
var pdfDocument = Document.Create(readBuffer, DocumentType.PDF, (int)Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi);
List<WriteableBitmap> imageList = new List<WriteableBitmap>();
for (int i = 0; i < pdfDocument.PageCount; i++)
{
    var size = pdfDocument.GetPageSize(i);
    var width = size.X;
    var height = size.Y;
    var image = new WriteableBitmap(width, height);
    IBuffer buf = new Buffer(image.PixelBuffer.Capacity);
    buf.Length = image.PixelBuffer.Length;
    pdfDocument.DrawPage(i, buf, 0, 0, width, height, false);
    using (var stream = buf.AsStream())
    {
        await stream.CopyToAsync(image.PixelBuffer.AsStream());
    }
    imageList.Add(image);
}

Pdf in Windows Phone 8.1

您可以尝试MuPDF:https://github.com/MishaUliutin/MuPDF.WinRT。

MuPDF.WinRT是一款轻量级的PDF、XPS和CBZ查看器解析器/渲染WinRT组件。

如果这不起作用。。也请看这个图书馆:http://www.xfiniumpdf.com/xfinium-pdf-downloads.html