Accusoft.PdfXpress5.Net
Load PDF from Memory
See Also Send Feedback
PDF Xpress 5 for .NET - User Guide > How To > Load PDF from Memory

Glossary Item Box

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. PDF Xpress saves all documents in PDF version 1.6.
C# Example Copy Code
// This code demonstrates loading a PDF document from memory 
PdfXpress pdfx = null;
Document document = null;
OpenOptions oo= null;
try
   {
        pdfx = new PdfXpress();
        pdfx.Initialize(null, null);  
        oo = new OpenOptions();
        byte[] buffer;
        IntPtr globalHandle;
        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 ex)
  {
  }
  finally
  {
         Marshal.FreeHGlobal(globalHandle);
         if ( null != document ) document.Dispose( );
         if ( null != oo ) oo.Dispose( );
         if ( null != pdfx ) pdfx.Dispose( );
 }

See Also

©2012. Accusoft Corporation. All Rights Reserved.