開啟來自字節的文件時發生錯誤"記憶體分配錯誤"

This article was translated from English: Does it need improvement?
Translated
View the article in English

處理大型 PDF 文件對某些企業而言至關重要。

當使用 IronPDF 載入現有 PDF 檔案時,IronPDF 會分配部分記憶體來儲存所載入的 PDF。 在 32 位元環境下運行的應用程式,每個進程的記憶體上限為 2 GB。 載入大於 500 MB 的 PDF 檔案可能會超過此限制,導致發生"分配錯誤"例外狀況。

例外訊息:

IronPdf.Exceptions.IronPdfNativeException: 'Error while opening document from bytes: 'bad allocation'.

解決方案

為解決此問題,請將應用程式設定為 64 位元模式執行。 這使應用程式能夠存取更大的記憶體空間,從而避免發生"記憶體分配錯誤"。 請依照以下步驟設定您的 Visual Studio 專案,使其針對 64 位元平台:

// 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
$vbLabelText   $csharpLabel

將平台目標設定為 x64 後,應用程式即可利用 64 位元系統擴增的記憶體容量,從而避免因處理大型 PDF 檔案而產生的記憶體分配問題。

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備開始了嗎?
Nuget 下載 19,014,616 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronPdf
執行範例 觀看您的 HTML 轉為 PDF。