Accusoft.PdfXpress7.Net
Load PDF from Memory

PDF Xpress™ supports opening a PDF document from memory.

To load an existing PDF file in memory:

  1. Create a new OpenOptions object.
  2. Create a new Document using a byte array containing the complete PDF file.
  3. Create a new Document using a handle to a Global Memory buffer containing the complete PDF file.
PDF Xpress can load any well-formed PDF up to PDF version 1.7.
C# Example
Copy Code
            // This code demonstrates loading a PDF document from memory
            PdfXpress pdfx = null;
            Document document = null;
            OpenOptions oo = null;
            IntPtr globalHandle = IntPtr.Zero;
            try
            {
                pdfx = new PdfXpress();
                pdfx.Initialize(null, null);
                oo = new OpenOptions();
                byte[] buffer;
               
                using (FileStream fs = new FileStream("C:\\test.pdf", FileMode.Open))
                {
                    buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, (int)fs.Length);
                    globalHandle = Marshal.AllocHGlobal((int)fs.Length);
                }
                Marshal.Copy(buffer, 0, globalHandle, buffer.Length);
                document = new Document(pdfx, oo, globalHandle);
            }
            catch (System.Exception)
            {
            }
            finally
            {
                Marshal.FreeHGlobal(globalHandle);
                if (null != document)
                {
                    document.Dispose();
                }
                if (null != pdfx)
                {
                    pdfx.Dispose();
                }
            }
See Also

 

 


©2018. Accusoft Corporation. All Rights Reserved.

Send Feedback