Universal App - PDFDraw.ExportAsync Sample code and how to know when image is rendered and written?

41 views
Skip to first unread message

tuan...@audiencemedia.com

unread,
Feb 10, 2015, 3:01:09 AM2/10/15
to pdfne...@googlegroups.com
Hello, I'm using PDFNet SDK 6.3.2

In sample code that I've found, only sample for PDFDraw.Export method, which is not supporting await and async.
I need to re-bind the image when the image of a PDF page is rendered, and finished written to file.

In my examination, PDFDraw.Export first create a 0 size image file, then when it finished render the image, the file size increased, only then, i can open the image, or bind it to UI. Now I need to know "when" this process complete.

Thanks in advance

Tomas Hofmann

unread,
Feb 13, 2015, 5:59:50 PM2/13/15
to pdfne...@googlegroups.com
Hi,

We have a PDFDraw.ExportAsync function.
You can use it in the same way as the Export function, with the exception that it doesn't take a file path.
Instead, you can create a RandomAccessStreamFilter. Here's an example of how to use it.

if (doc != null)
{
StorageFile outfile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Temp.png", CreationCollisionOption.GenerateUniqueName);
IRandomAccessStream stream = await outfile.OpenAsync(FileAccessMode.ReadWrite);
IFilter filter = new RandomAccessStreamFilter(stream);

PDFDraw draw = new PDFDraw();
Page page = doc.GetPage(1);
ObjSet hintSet = new ObjSet();
Obj encoderParam = hintSet.CreateDict();
encoderParam.PutNumber("Quality", 80);

await draw.ExportAsync(page, filter, "png", encoderParam);
System.Diagnostics.Debug.WriteLine("Exported page 1 to: " + outfile.Path);
}

There appears to be a bug in 6.3.2 if you use ExportAsync with only 3 parameters, or make the 4th parameter null. We will fix this for future versions.
Instead, you can just leave the encoderParam object alone and not add any numbers before you use it.


Another option, if you prefer to use a file path, is to just stick the Export function inside a task you create yourself:
await Task.Run(() =>
{
draw.Export(page, System.IO.Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "Exported.png"));
});

If this does not help, please let us know what you are trying to do.

Best Regards,
Tomas Hofmann
Reply all
Reply to author
Forward
0 new messages