Avoid loading the stream into memory

Product: PDFTronDotNet

Product Version: 9.0.0.0

Please give a brief summary of your issue:
(Think of this as an email subject)
Avoid loading the stream into memory

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

We use PDFDoc object to analyse the PDF files, for example to check if file has signatures:

 public bool HasSignatures(Stream pdfStream)
    {
        var document = new PDFDoc(pdfStream);

        bool hasSignatures = document.HasSignatures();

        return hasSignatures;
    }

We use streams to avoid loading whole file content into the memory, however, the PDFDoc object loads whole file into the memory, even if the stream is sent, causing OutOfMemoryExcepiton being thrown when analyzing huge files.

It it possible to analyse the PDF file (by using PDFDoc) without loading the whole file into the memory?

No, the PDF format precludes this, except in a very narrow sitatuations/use cases of just viewing/rendering linearized PDF files.

In general the PDF file format requires random access to the entire file to do things like check Digital Signatures.

The best way to avoid memory consumption is to write the file to disk, and give the PDFDoc constructor the file path, then PDFNet will only load the minimum data needed to complete the API requests.

1 Like