Glyph & Cog, LLC
search:  
 
     


Home
Products
Services
Tips & Misc
Buy
Tech Support
Company
Contact
 

How do I use the loadStream function with .NET?

Applies to: XpdfInfo, XpdfText, XpdfViewer, XpdfPrint, XpdfRasterizer, XpdfAnalyze, XpdfPS, XpdfImageExtract

The loadStream function allows you to read a PDF file from an OLE Stream object instead of reading a file from disk. To use it from a .NET development environment, you'll need to create an OLE Stream object. Here is sample VB.NET code:

Imports System.Runtime.InteropServices

...

Declare Function CreateStreamOnHGlobal Lib "ole32" _
                    (ByVal hGlobal As IntPtr, _
                     ByVal fDeleteOnRelease As Boolean, _
                     ByRef ppstm As UCOMIStream) As Long

...

' Create the Stream ("UCOMIStream" in .NET) object.
Dim str As UCOMIStream = Nothing
CreateStreamOnHGlobal(Nothing, True, str)

' Copy buf (a Byte array containing a PDF file) into the stream.
str.Write(buf, buf.Length, Nothing)

' Load the PDF stream into XpdfViewer.
viewer.loadStream(str)

IMPORTANT: The Stream object must be kept valid as long as XpdfViewer (or another G&C component) has the PDF file open. Do not delete the Stream until you are done with that PDF file.

 
   
    Copyright 2008 Glyph & Cog, LLC