We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Support non-seekable streams in Aspose.Pdf

Many streams do not support seeking. ie CanSeek returns false and Seek() throw an exception

For example when reading a stream from a database.

In these case the only workaround is to read the entire stream into a memorystream. The problem with this is that the entire byte array needs to read into memory. for large files this severely effects the performance of an app, and has a negative impact the GC.

Can support for non-seekable streams be added?

@simoncropp

Thanks for contacting support.

Would you kindly share some sample PDF document along with code snippet through which we can observe the performance issue and need of non-seekable streams. We will investigate it in our environment and address it accordingly.

    [Test]
    public void Run()
    {
        using (var inputStream = File.OpenRead(docPath))
        {
            var pdfDocument = new Document(new NonSeekableStream(inputStream));
        }
    }

class NonSeekableStream : Stream
{
    Stream inner;

    public NonSeekableStream(Stream inner)
    {
        this.inner = inner;
    }

    public override void Flush()
    {
        inner.Flush();
    }

    public override long Seek(long offset, SeekOrigin origin)
    {
        throw new System.NotImplementedException();
    }

    public override void SetLength(long value)
    {
        throw new System.NotImplementedException();
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        return inner.Read(buffer, offset, count);
    }

    public override void Write(byte[] buffer, int offset, int count)
    {
        throw new System.NotImplementedException();
    }

    public override bool CanRead => inner.CanRead;
    public override bool CanSeek => false;
    public override bool CanWrite => false;
    public override long Length => inner.Length;

    public override long Position
    {
        get => inner.Position;
        set => throw new System.NotImplementedException();
    }
}

@simoncropp

A feature request has been logged in our issue tracking system as PDFNET-47805. We will further investigate the feasibility of required support and keep you posted with the status of its availability. Please be patient and spare us some time.

We are sorry for the inconvenience.