2016-08-25 3 views
0

bitmiracle.docotic.pdf 라이브러리 (평가판)를 사용하여 PDF 파일을 병합하고 압축하려고하며 크기가 700MB 인 병합 파일의 경우 "메모리 부족"예외가 발생했습니다. 아래 내용은 내 코드PDF 병합 및 파일 압축.

/// <summary> 
    /// Open file for copy. 
    /// </summary> 
    /// <param name="file">File name.</param> 
    /// <param name="outputDocument">Output pdf document.</param> 
    private void OpenFileForCopy(string file, PdfDocument outputDocument) 
    { 
     if (isFirstFile) 
     { 
      outputDocument.Open(file); 
     } 
     else { 
      outputDocument.Append(file); 
     } 
    } 

    /// <summary> 
    /// Saves PDF merged pdf file to location specified. 
    /// </summary> 
    /// <param name="outputDocument">Merged pdf document.</param> 
    /// <param name="path">Path to be stored.</param> 
    /// <param name="source">Source of file.</param> 
    /// <param name="Number">Number.</param> 
    private string[] SavePDF(PdfDocument outputDocument, string path, string source, string Number) 
    { 
     string[] result = new string[2]; 
     outputDocument.PageLayout = PdfPageLayout.SinglePage; 
     string newPath = path + "_" + "Merged"; 
     string nor= Number.Substring(1); 
     Directory.CreateDirectory(newPath); 
     newPath += "\\Stmt" + source + nor+ ".pdf"; 
     outputDocument.SaveOptions.Compression = BitMiracle.Docotic.Pdf.PdfCompression.Flate; 
     outputDocument.SaveOptions.UseObjectStreams = true; 
     outputDocument.SaveOptions.RemoveUnusedObjects = true; 
     outputDocument.SaveOptions.OptimizeIndirectObjects = false; 
     outputDocument.SaveOptions.WriteWithoutFormatting = true; 

     outputDocument.Save(newPath); 
     outputDocument.Dispose(); 
     isFirstFile = true; 
     result[0] = source ; 
     result[1] = Convert.ToString(fileCount); 
     fileCount = 0; 
     return result; 
    } 
PdfDocument의 인스턴스가 발생

이 방법을 통해 사용할 수

친절

아무것도 수정

감사 할 필요가있는 경우 알려주세요 Kirankumar

+0

프로세스에 대한 자세한 정보를 제공해주십시오. 32 비트 또는 64 비트 프로세스입니까? 어떤 버전의 .NET Framework를 사용하고 있습니까? 얼마나 많은 파일을 병합합니까? – Bobrovsky

+0

자사의 64 비트 머신, .net 4.6.1 및 파일 수는 1에서 200까지 다르며 각 파일의 최대 페이지 수는 5 개입니다 –

답변

0

코드는 정상입니다. 라이브러리가 소비하는 메모리 양은 총 크기와 추가 된 문서 수에 비례한다는 점에 유의하십시오.

라이브러리에서 사용하는 메모리 양을 줄이기 위해 문서를 한 번 저장하고 다시 열어 보는 것이 좋습니다. 중간 저장을 위해 다음 설정을 사용할 수도 있습니다. (중간 저장)

  1. 문서 열기
  2. 추가] 이하 10 (또는 다른 번호) 문서
  3. 문서 저장 : 그래서

    outputDocument.SaveOptions.UseObjectStreams = false; 
    

    , 나는 다음과 같은 과정을 시도하는 제안

  4. 방금 ​​저장 한 문서 열기
  5. 다음 문서 배치 추가
  6. ...

현재 버전의 라이브러리는 제안 된 프로세스가 사용되는 경우에도 예외 메모리 부족을 초래할 수 있습니다.