PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Out of memory exception pdfreader.open().pages[0]
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4110
Page 1 of 1

Author:  Lokeshlehkara [ Thu Mar 12, 2020 2:09 am ]
Post subject:  Out of memory exception pdfreader.open().pages[0]

I have a fairly large PDF document (more than 1 GB) but I am only concerned with the first page of it. I was doing the following in order to avoid taking complete PDF in memory.

PdfPage inputpdf = PdfReader.Open(filepath).Pages[0];
But even this is not working and I am getting system out of memory exception every other time. Any thoughts on how to work with large file without storing the complete information in memory. All I am looking for is one page.

Below is stack trace.

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at PdfSharp.Pdf.IO.Lexer.ReadStream(Int32 length)
at PdfSharp.Pdf.IO.Parser.ReadObject(PdfObject pdfObject, PdfObjectID objectID, Boolean includeReferences, Boolean fromObjecStream)
at PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openmode, PdfPasswordProvider passwordProvider)
at PdfSharp.Pdf.IO.PdfReader.Open(String path, String password, PdfDocumentOpenMode openmode, PdfPasswordProvider provider)
P.S. I am working on .NET Core, Azure function EP1 model. (3.5 GB memory).using pdfsharp nuget package 1.50.5147

Author:  TH-Soft [ Thu Mar 12, 2020 4:32 pm ]
Post subject:  Re: Out of memory exception pdfreader.open().pages[0]

Already discussed on SO:
https://stackoverflow.com/a/60639529/162529

PDFsharp reads the whole document when you call PdfReader.Open() and appending .Pages[0] does not reduce the required memory at all.

If your code runs in 32 bit mode then try switching to 64 bit mode to break the 2 GB barrier.

If that does not help then consider upgrading your Azure model to include more memory or maybe try a different tool other than PDFsharp.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/