在WinRt应用程序中我想显示pdf内容。为此,我将所有的PDF页面转换为图像。但质量非常糟糕。同样在缩放之后,它变得更多bader。WinRt将PDF转换为图像提高图像质量
我该如何提高质量!?可以使用编码器?或者我需要更高的Widht/Hight值?
StorageFile pdfFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
//Load Pdf File
pdfDocument = await PdfDocument.LoadFromFileAsync(pdfFile);
if (pdfDocument != null && pdfDocument.PageCount > 0) {
//Get Pdf page
for (int pageIndex = 0; pageIndex < pdfDocument.PageCount; pageIndex++) {
var pdfPage = pdfDocument.GetPage((uint)pageIndex);
if (pdfPage != null) {
// next, generate a bitmap of the page
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
StorageFile pngFile = await tempFolder.CreateFileAsync(Guid.NewGuid().ToString() + ".png", CreationCollisionOption.ReplaceExisting);
if (pngFile != null) {
IRandomAccessStream randomStream = await pngFile.OpenAsync(FileAccessMode.ReadWrite);
PdfPageRenderOptions pdfPageRenderOptions = new PdfPageRenderOptions();
pdfPageRenderOptions.IsIgnoringHighContrast = false;
PdfPageDimensions rotation = pdfPage.Dimensions;
Size pdfPageSize = pdfPage.Size;
if (pdfPageSize.Height > 1000) {
pdfPageRenderOptions.DestinationHeight = (uint)(pdfPageSize.Height * 0.85);
}
else if (pdfPageSize.Width > 1000) {
pdfPageRenderOptions.DestinationWidth = (uint)(pdfPageSize.Width * 1.25);
}
await pdfPage.RenderToStreamAsync(randomStream, pdfPageRenderOptions);
await randomStream.FlushAsync();
randomStream.Dispose();
pdfPage.Dispose();
PdfPagePath = pngFile.Path;
PdfPagesPathCollection.Add(pngFile.Path);
}
}
}
}
你为什么将它们转换为图像? Pdf是一种可缩放的矢量格式。 – WiredPrairie
我需要使用它,将它们显示在winrt应用程序中并允许缩放。如果我保留PDF格式,处理和直接在应用程序中显示更加困难。 – GermanSniper
通过将其转换为高分辨率位图,您的应用程序可能会消耗大量的内存,这可能会导致应用程序被终止。 – WiredPrairie