2011-04-05 3 views
1

친애하는 팀 내 응용 프로그램에서 itextsharp를 사용하여 pdf를 분할하고 싶습니다. 내가 PDF 파일을 업로드하는 경우 분할을 위해 파일 크기가 10MB 인 10 페이지가 포함되어 있습니다. 각 PDF 파일의 결합 파일 크기를 분할하면 20MB 이상의 파일 크기가됩니다. 가능한 경우 파일 크기를 줄입니다 (각 pdf).iTextSharp를 사용할 때 분할 된 PDF 크기가 더 크다

제발 도와주세요.

미리 감사드립니다.

+0

입력 및 출력 PDF를 볼 수 있습니까? –

답변

0

작가에게 압축 설정을 시도 했습니까?

Document doc = new Document(); 
    using (MemoryStream ms = new MemoryStream()) 
    { 
     PdfWriter writer = PdfWriter.GetInstance(doc, ms); 
     writer.SetFullCompression(); 
    } 
1

이것은 파일의 리소스와 관련이있을 수 있습니다. 원본 문서가 각각의 글꼴에 포함 된 글꼴을 사용하는 경우 원본 파일에 글꼴 인스턴스가 하나만 존재합니다. 분할 할 때 각 파일에는 해당 글꼴도 있어야합니다. 총 오버 헤드는 n 페이지 × (각 글꼴)입니다. 이런 종류의 팽창을 일으키는 요소에는 글꼴, 이미지, 색상 프로파일, 문서 템플릿 (일명 양식), XMP 등이 포함됩니다.

그리고 즉각적인 문제를 해결하는 데 도움이되지 않지만 PDF 도구

PdfDocument.Separate(userpassword, ownerpassword, origPath, destFolder, "Separated Page{0}.pdf", true); 

오리지널 파일에서 PDF를 타고 이명 령 폴더에 새로운 페이지 패턴과 이름이 각을 생성합니다 : Atalasoft dotImage에, 당신의 작업은 1 라이너가된다. 마지막에있는 bool은 기존 파일을 덮어 쓰는 것입니다.

면책 조항 : 저는 Atalasoft에서 일하고 PDF 라이브러리 (Acrobat 버전 1, 2, 3 및 4에서 Adobe에서 근무 했었습니다)를 작성했습니다.

0

안녕 얘들 아 난 PDF 파일을 여러 개의 PDF 파일로 분할 위의 코드를 수정.

 iTextSharp.text.pdf.PdfReader reader = null; 
     int currentPage = 1; 
     int pageCount = 0; 
     //string filepath_New = filepath + "\\PDFDestination\\"; 

     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); 
     //byte[] arrayofPassword = encoding.GetBytes(ExistingFilePassword); 
     reader = new iTextSharp.text.pdf.PdfReader(filepath); 
     reader.RemoveUnusedObjects(); 
     pageCount = reader.NumberOfPages; 
     string ext = System.IO.Path.GetExtension(filepath); 
     for (int i = 1; i <= pageCount; i++) 
     { 
      iTextSharp.text.pdf.PdfReader reader1 = new iTextSharp.text.pdf.PdfReader(filepath); 
      string outfile = filepath.Replace((System.IO.Path.GetFileName(filepath)), (System.IO.Path.GetFileName(filepath).Replace(".pdf", "") + "_" + i.ToString()) + ext); 
      reader1.RemoveUnusedObjects(); 
      iTextSharp.text.Document doc = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage)); 
      iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.Create)); 
      doc.Open(); 
      for (int j = 1; j <= 1; j++) 
      { 
       iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader1, currentPage); 
       pdfCpy.SetFullCompression(); 
       pdfCpy.AddPage(page); 
       currentPage += 1; 
      } 
      doc.Close(); 
      pdfCpy.Close(); 
      reader1.Close(); 
      reader.Close(); 

     } 
관련 문제