The OpenAsync and OpenExAsync methods open a PDF document from file or a WinRT stream. The Open method reads all the file contents into memory and closes the file right-away. The OpenEx method opens each page as it is requested, keeping the file handle open. OpenEx has the advantage of being more efficient but prevents other applications from writing to the file while it is being viewed.
Public Function OpenAsync(filename As String, pwd As String) As Windows.Foundation.IAsyncOperation(Of Boolean)
Public Function OpenExAsync(filename As String, pwd As String) As Windows.Foundation.IAsyncOperation(Of Boolean)
Public Function OpenAsync(file As Windows.Storage.StorageFile, pwd As String) AsWindows.Foundation.IAsyncOperation(Of Boolean)
Public Function OpenAsync(stream As Windows.Storage.Streams.IRandomAccessStream, pwd As String) As Windows.Foundation.IAsyncOperation(Of Boolean)
public Windows.Foundation.IAsyncOperation<bool> OpenAsync(string filename, string pwd);
public Windows.Foundation.IAsyncOperation<bool> OpenExAsync(string filename, string pwd);
public Windows.Foundation.IAsyncOperation<bool> OpenAsync(Windows.Storage.StorageFile file, string pwd);
public Windows.Foundation.IAsyncOperation<bool> OpenAsync(Windows.Storage.Streams.IRandomAccessStreamstream, string pwd);
public: Windows::Foundation::IAsyncOperation<bool>^ OpenAsync (String^ filename, String^ pwd);
public: Windows::Foundation::IAsyncOperation<bool>^ OpenExAsync(String^ filename, String^ pwd);
public: Windows::Foundation::IAsyncOperation<bool>^ OpenAsync(Windows::Storage::StorageFile^filename, String^ pwd);
public: Windows::Foundation::IAsyncOperation<bool>^ OpenAsync(Windows::Storage::Streams::IRandomAccessStream^stream, String^ pwd);
Windows.Foundation.IAsyncOperation<boolean> openAsync(Windows.Storage.Streams.IRandomAccessStream stream, String pwd);
filename
Path of the file to open. This method overload can only be used with files stored on folders where Windows Store applications have reading permissions, such as:
Windows.ApplicationModel.Package.Current.InstalledLocation
Windows.Storage.ApplicationData.Current.LocalFolder
ApplicationData.Current.TemporaryFolder
file
A StorageFile object that represents the file to open.
stream
Path A stream object that contains the content of the file to open.
pwd
Password to use if document is protected.
Asynchronous operation that returns a boolean on termination.
The return value of the asynchronous operation is True if document opened successfully, False otherwise.
Member of AmyuniPDFCreator.IacDocument.
The following example shows how to check if a document is protected and ask the user for the corresponding password.
IacDocument document = fPDFCreator.Document;
// Set the license key
document.SetLicenseKey("Company Name", "07EFCDAB0100...009EE2F79");
// Selecting a file using a Windows Runtime dialog
var filePicker1 = new Windows.Storage.Pickers.FileOpenPicker();
filePicker1.FileTypeFilter.Add(".pdf");
var selectedFile = await filePicker1.PickSingleFileAsync();
// Loading the file asynchronously
bool result = await document.OpenAsync(selectedFile, "");
// If the file could not be loaded, then the value of property IacDocument.Protected will be 1
if ( result == false && document.Protected == 1 )
{
// Loading the file again using a password
String password = "ownerPass";
result = await document.OpenAsync(selectedFile, password);
}
auto pdfDoc = pdfControl->Document;
// Set the license key
pdfDoc->SetLicenseKey ("Amyuni Tech", "07EFCDAB0100...009EE2F79");
// Selecting a file using a Windows Runtime dialog
auto filePicker = ref new Windows::Storage::Pickers::FileOpenPicker();
filePicker->FileTypeFilter->Append(".pdf");
// TODO: Error checking and exception handling
task<void> pickFileTask = create_task( filePicker->PickSingleFileAsync() ).
then([=](Windows::Storage::StorageFile^ selectedFile)
{
// Loading the file asynchronously
create_task(pdfDoc->OpenAsync(selectedFile, "")).
then( [=](bool succeded)
{
// If the file could not be loaded, then the value of property IacDocument.Protected will be 1
if(!succeded && pdfDoc->Protected == 1)
{
// Loading the file again using a password
String^ password = L"ownerPass";
create_task(pdfDoc->OpenAsync(selectedFile, password));
}
});
});
var pdfDoc = new AmyuniPDFCreator.IacDocument();
// Set the license key
pdfDoc.setLicenseKey("Amyuni PDF Creator WinRT-UWP Evaluation", "07EFCDAB0100...009EE2F79");
// Selecting a file using a Windows Runtime dialog
var filePicker1 = new Windows.Storage.Pickers.FileOpenPicker();
filePicker1.fileTypeFilter.append(".pdf");
filePicker1.pickSingleFileAsync().
then(function (selectedFile)
{
// Loading the file asynchronously
selectedFile.openAsync(Windows.Storage.FileAccessMode.read).
then(function (inStream)
{
// If the file could not be loaded, then the value of property IacDocument.Protected will be 1
pdfDoc.openAsync(inStream, "").
done(function (openSuccedded)
{
// If the file could not be loaded, then the value of property IacDocument.Protected will be 1
if (!openSuccedded && pdfDoc.protected == 1)
{
// Loading the file again using a password
var password = "ownerpass";
pdfDoc.openAsync(inStream, password);
}
});
});
});