2017-12-11 17 views
0

Aspose를 처음 접했을 때 아래의 경우 도움이 필요합니다.
여러 개의 PDF를 Aspose를 사용하여 1 개의 PDF로 병합하고 싶지만 쉽게 할 수 있지만 문제는 PDF 크기를 200MB로 제한하고 싶습니다.
즉, 내 병합 된 PDF 크기가 200MB보다 큰 경우 PDF를 여러 PDF로 분할해야합니다. 예를 들어, 병합 된 PDF의 크기가 300MB이면 첫 번째 PDF는 200MB이고 두 번째 PDF는 100MB이어야합니다.Aspose를 사용하여 크기에 따라 PDF 병합

주요 문제는 아래의 코드에서 문서의 크기를 찾을 수 없다는 것입니다. 아래 코드를 사용하고 있습니다. 크기에 따라 PDF를 병합

Document destinationPdfDocument = new Document(); 
       Document sourcePdfDocument = new Document(); 

      //Merge PDF one by one 
      for (int i = 0; i < filesFromDirectory.Count(); i++) 
      { 
       if (i == 0) 
       { 
        destinationPdfDocument = new Document(filesFromDirectory[i].FullName); 
       } 
       else 
       { 
        // Open second document 
        sourcePdfDocument = new Document(filesFromDirectory[i].FullName); 

        // Add pages of second document to the first 
        destinationPdfDocument.Pages.Add(sourcePdfDocument.Pages); 


        //** I need to check size of destinationPdfDocument over here to limit the size of resultant PDF** 

       } 
      } 

      // Encrypt PDF 
      destinationPdfDocument.Encrypt("userP", "ownerP", 0, CryptoAlgorithm.AESx128); 

      string finalPdfPath = Path.Combine(destinationSourceDirectory, destinatedPdfPath); 

      // Save concatenated output file 
      destinationPdfDocument.Save(finalPdfPath); 

다른 방법도 알 수있다.
덕분에 사전

답변

0

에서 나는 물리적으로 저장하기 전에 PDF 파일 크기를 결정하는 직접적인 방법이 없다는 것을 두려워한다. 따라서 문제 추적 시스템에 PDFNET-43073이라는 기능 요청을 이미 기록했으며 제품 팀에서이 기능의 타당성을 조사했습니다. 기능을 사용할 수 있는지에 대한 중요한 업데이트가있는대로 알려 드리겠습니다. 잠시만 시간을 내주세요.

그러나 해결 방법으로 문서를 메모리 스트림에 저장하고 원하는 PDF 크기를 초과하는지 여부에 관계없이 메모리 스트림의 크기를 확인할 수 있습니다. 위의 방법으로 원하는 크기의 200MB 크기의 PDF를 생성 한 다음 코드 스 니펫을 확인하십시오.

//Instantiate document objects 
Document destinationPdfDocument = new Document(); 
Document sourcePdfDocument = new Document(); 

//Load source files which are to be merged 
var filesFromDirectory = Directory.GetFiles(dataDir, "*.pdf"); 

for (int i = 0; i < filesFromDirectory.Count(); i++) 
{  
if (i == 0) 
{ 
destinationPdfDocument = new Document(filesFromDirectory[i]); 
} 
else 
{ 
// Open second document 
sourcePdfDocument = new Document(filesFromDirectory[i]); 
// Add pages of second document to the first 
destinationPdfDocument.Pages.Add(sourcePdfDocument.Pages); 
//** I need to check size of destinationPdfDocument over here to limit the size of resultant PDF** 
MemoryStream ms = new MemoryStream(); 
destinationPdfDocument.Save(ms); 
long filesize = ms.Length; 
ms.Flush(); 
// Compare the filesize in MBs 
if (i == filesFromDirectory.Count() - 1) 
{ 
    destinationPdfDocument.Save(dataDir + "PDFOutput_" + i + ".pdf"); 
} 
else if ((filesize/(1024 * 1024)) < 200) 
continue; 
else 
{ 
    destinationPdfDocument.Save(dataDir + "PDFOutput_" + i.ToString() + ".pdf"); 
    destinationPdfDocument = new Document(); 
} 
} 
} 

이 정보가 도움이되기를 바랍니다. 추가 도움이 필요하면 저희에게 알려주십시오.

저는 Aspose with Developer Evangelist에서 일합니다.