How can I open a PDF that I'm streaming over the network?


We are trying to stream files from FTP to a PDFDoc. Is there any way to directly get the file buffer data into PDFDoc object without creating any file on local file system, and without putting the entire document into a memory buffer? Here’s our code:

InputStream is = ftp.retrieveFileStream(remote_file);
byte[] buffer = new byte[nBufferSize];
int n;
while ((n = > 0)



You should be able to subclass InputStream, using the code you quoted above as a starting point:

Simply implement the InputStream methods (i.e., You would need to populate your byte buffer from the network (as in your code sample, using when the buffer is empty. Then return the requested bytes to the InputStream’s consumer (i.e., the code that called, keeping track of where you are in the buffer. When no more bytes are available, repopulate the buffer from the network.

You can then instantiate a PDFDoc from the InputStream: