Error while opening document from bytes 'bad allocation'
Processing large PDF documents can be crucial for some businesses.
When using IronPDF to load an existing PDF file, IronPDF allocates a portion of memory to store the loaded PDF. Applications running on 32-bit have a memory limit of 2 GB per process. Loading a PDF file larger than 500 MB can exceed this limitation, resulting in a 'bad allocation' exception.
Exception message:
IronPdf.Exceptions.IronPdfNativeException: 'Error while opening document from bytes: 'bad allocation'.
Solution
To solve this, please set the application to run on 64-bit. This allows the application to access a larger memory space, avoiding the 'bad allocation' error. Follow these steps to configure your Visual Studio project to target a 64-bit platform:
// Open your project in Visual Studio
// In the Solution Explorer, right-click on your project and select 'Properties'
// Navigate to the 'Build' tab
// Select 'x64' from the 'Platform target' dropdown
<PropertyGroup>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
// Save your changes and rebuild the project
// Open your project in Visual Studio
// In the Solution Explorer, right-click on your project and select 'Properties'
// Navigate to the 'Build' tab
// Select 'x64' from the 'Platform target' dropdown
<PropertyGroup>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
// Save your changes and rebuild the project
' Open your project in Visual Studio
' In the Solution Explorer, right-click on your project and select 'Properties'
' Navigate to the 'Build' tab
' Select 'x64' from the 'Platform target' dropdown
(Of PropertyGroup) (Of PlatformTarget) x64</PlatformTarget> </PropertyGroup>
' Save your changes and rebuild the project
By setting the platform target to x64, the application can utilize the expanded memory capacity of a 64-bit system, thereby preventing memory allocation issues related to large PDF files.