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
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();
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.