Issue when opening a PDF using PDFTron WinRT (Windows 8 Metro) mobile SDK

Q:

I using PDFTron WinRT (Windows 8 metro) Mobile Sdk to load and view PDF. When I try to open PDF doc

Me._MyDoc = New PDFDoc(FilePath)

When FilePath of my pdf file in in myDocument then it gives an exception “Parameter is incorrect”; Although we add Documents Library in the capability of the project. When we open the pdf file as stream then use this stream in pdfdoc constructor → it works. I have the same problem when using the export function of the Draw class.

A:

Only files within the application’s sandbox can be loaded by using the filepath directly (i.e. passing the filepath as string to PDFDoc). If you wish to load a file that is not within the application’s sandbox, you will need to pass it as an IRandomAccessStream instance. These are restrictions posed on all WinRT apps.

Q: Thank you for your help, what about the draw.export() function that exports a pdf page as a bitmap. I want to save the file to my documents, is it possible. Please how (because in the examples I downloaded it is saving on the same folder as the application.

A:

You should be able to use the PDFDraw.ExportAsStreamAsync which would give you an IRandomAccessStream instance which you can eventually write to file. Please keep in mind that when developing for Windows Store Apps, you will need to use the FileSavePicker Class (http://msdn.microsoft.com/library/windows/apps/BR207871) in order to write outside the application’s local folders. For example:

var pdfDraw = new PDFDraw();
var page1 = pdfDoc.GetPage(1);
using (var imageStream = await pdfDraw.ExportAsStreamAsync(page1, “PNG”))
using (var imageStreamRead = imageStream.AsStreamForRead())
{
var savePicker = new FileSavePicker();
savePicker.FileTypeChoices.Add(“Portable Network Graphics”, new List() { “.png” });
var saveFileStorage = await savePicker.PickSaveFileAsync();
if (saveFileStorage != null)
{
using (var saveFileStream = await saveFileStorage.OpenAsync(FileAccessMode.ReadWrite))
using (var saveFileStreamWrite = saveFileStream.AsStreamForWrite())
{
await imageStreamRead.CopyToAsync(saveFileStreamWrite);
}
}
}

On Wednesday, February 27, 2013 10:35:03 AM UTC-8, Support wrote:

Q:

I using PDFTron WinRT (Windows 8 metro) Mobile Sdk to load and view PDF. When I try to open PDF doc

Me._MyDoc = New PDFDoc(FilePath)

When FilePath of my pdf file in in myDocument then it gives an exception “Parameter is incorrect”; Although we add Documents Library in the capability of the project. When we open the pdf file as stream then use this stream in pdfdoc constructor → it works. I have the same problem when using the export function of the Draw class.


A:

Only files within the application’s sandbox can be loaded by using the filepath directly (i.e. passing the filepath as string to PDFDoc). If you wish to load a file that is not within the application’s sandbox, you will need to pass it as an IRandomAccessStream instance. These are restrictions posed on all WinRT apps.