I want to covert first page of pdf to image to display on gridview. After i select the image, the pdf open based on the image that i selected. How to convert first page of pdf to image on windows phone 8.1?
Asked
Active
Viewed 135 times
-1
-
Do you have a pdf viewer implemented in your app? Or do you use third party application to display the pdf? – xmashallax May 13 '15 at 17:16
-
I use component one to read the pdf – user3431268 May 13 '15 at 17:17
-
http://stackoverflow.com/questions/20280120/how-to-programatically-take-a-screenshot-on-windows-phone maybe you can try this? – xmashallax May 13 '15 at 17:21
-
Not with button and not a sceenshot. But, after i downlod the pdf from the server, the pdf automatically convert first page of pdf to image and displayed it on gridview – user3431268 May 13 '15 at 17:30
1 Answers
0
I think a library called MuPDF is a way to go. I found an old sample project for WinRT (Reading PDF file in Windows store App) that contains a simple PDF viewer and it basically converts each page to a WriteableBitmap which is then displayed on the screen.
Here is a part of the code that does this:
async Task<WriteableBitmap> ConstructPageAsync()
{
var size = Document.GetPageSize(PageNumber);
var width = (int)(size.X * ZoomFactor);
var height = (int)(size.Y * ZoomFactor);
var image = new WriteableBitmap(IsDoublePage ? width * 2 : width, height);
IBuffer buf = new Buffer(image.PixelBuffer.Capacity);
buf.Length = image.PixelBuffer.Length;
if (IsDoublePage)
{
await Task.Run(() => Document.DrawFirtPageConcurrent(PageNumber, buf, width, height));
await Task.Run(() => Document.DrawSecondPageConcurrent(PageNumber + 1, buf, width, height));
}
else
{
Document.DrawPage(PageNumber, buf, 0, 0, width, height, false);
}
// copy the buffer to the WriteableBitmap ( UI Thread )
using (var stream = buf.AsStream())
{
await stream.CopyToAsync(image.PixelBuffer.AsStream());
}
return image;
}
It needs some work to make it work in Windows Phone 8.1 but I think it's a good start.
Lukáš Neoproud
- 872
- 3
- 10
- 20
-
I have been use mupdf to to convert first page pf pdf to image, but once i submit the application to windows phone store, the application was rejected because MuPDFWinRT.dll has failed ContainerCheck check – user3431268 May 14 '15 at 04:11
-
I coudn't find any other free library. XFINIUM.PDF seems good, their sample app worked well. Unfortunately it costs about $500. – Lukáš Neoproud May 17 '15 at 14:01