如何避免itextsharp中的高内存消耗

时间:2014-03-20 10:48:25

标签: vb.net itextsharp

这里AddPage()方法在创建pdf时消耗更多内存(In Bytes [])。创建pdf后它没有被释放。我尝试使用freereader()方法但没有用。请建议我如何释放内存或消耗更少内存的方法

Public Sub AddStampedPagesToDocument(ByVal stamperStream As MemoryStream)
    Dim documentReader As PdfReader

    If stamperStream IsNot Nothing Then
        mStamper.FormFlattening = True
        mStamper.Close()
        documentReader = New PdfReader(stamperStream.ToArray)

        If (mOutputWriter Is Nothing) Then
            mOutputDocument = New Document(documentReader.GetPageSizeWithRotation(1))
            mOutputWriter = New PdfCopy(mOutputDocument, mOutputStream)
            mOutputDocument.Open()
        End If

        For pageCount As Integer = 1 To mFormReader.NumberOfPages
            mOutputWriter.AddPage(mOutputWriter.GetImportedPage(documentReader, pageCount))
            mOutputDocumentPageCount += 1
        Next

        mStamperStream = stamperStream
        mOutputWriter.FreeReader(documentReader)
    End If
End Sub

0 个答案:

没有答案