Open a PDF in UWP
To open a PDF document.
// open document from the filesystem
PDFDoc doc = new PDFDoc(fileName);
// optionally read a PDF document from a stream
MappedFile file = new MappedFile(fileName);
PDFDoc documentStream = new PDFDoc(file);
// or pass-in a memory buffer
ulong fileSize = file.WinRTGetFileSize();
FilterReader fileReader = new FilterReader(file);
byte[] memoryBuffer = new byte[(int)fileSize];
long bytesRead = fileReader.Read(memoryBuffer);
PDFDoc documentMemory = new PDFDoc(memoryBuffer);
// load from a URL
Uri url = new Uri("https://myserver.com/myfile.pdf");
HttpClient client = new HttpClient();
var file_content = client.GetByteArrayAsync(url);
PDFDoc doc = new PDFDoc(new MemoryStream(file_content));Read & write a PDF file from/to memory buffer Full source code which illustrates how to read/write a PDF document from/to memory buffer. This is useful for applications that work with dynamic PDF documents that don't need to be saved/read from a disk.
About opening a document
The PDFDoc constructor creates a PDF document from scratch:
A newly-created document does not yet contain any pages. See the accessing pages section for details on creating new pages and working with existing pages.
Using Apryse SDK, you can open a document from a serialized file, from a memory buffer, or from a Filter stream.
To open an existing PDF document from a file, specify its file path in the PDFDoc constructor:
Here's how to open an existing PDF document from a memory buffer:
It's also easy to open a PDF document from a MemoryFilter or a custom Filter .
After creating a PDFDoc object, it's good practice to call InitSecurityHandler() on it. If the document is encrypted, calling the method will decrypt it. If the document is not encrypted, calling the method is harmless.
Last updated
Was this helpful?