2011-10-07 3 views
2

많은 rdlc 보고서를 .net 프레임 워크의 하나의 큰 pdf로 병합하여 보고서 책을 만드는 방법이 있습니까? 보통 우리는 pdfs를 rdlc 보고서로 생성하기 위해 Datasource를 전달한 다음 pdf 형식으로 렌더링합니다. 그래서 렌더링하는 동안 여러 rdlc가 pdfs를 병합 할 수 있습니까? SSRS (SQL Server Reporting Service)를 사용하여 생성 된 pdfs를 병합 할 수있는 도구가 있습니까?SSRS 및 ASP.NET을 사용하여 Pdf 형식으로 생성 된 보고서 병합

답변

0

http://khsw.blogspot.com/2006/04/merge-pdf-files-using-itextsharp.html에 코드를 사용하여 여러 기존 PDF를 단일 문서로 병합했습니다.

+0

위의 내용은 pdf가 물리적으로 존재하고 병합되어야 함을 요구합니다. 만약 우리가 merge하기 위해 pdf로 localreport를 렌더링하는 바이트 스트림을 사용하고 pdf로 렌더링하는 것은 가능합니다. – zain

+0

바이트 배열로 작업 할 수 있습니까? http://pastebin.com/qbw95cad –

0

PDF를 iTextSharp와 병합 할 수 있다는 것을 알고 있습니다. 다음과 같이 시도하십시오.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 

using iTextSharp.text; 
using iTextSharp.text.pdf; 

namespace Components.Pdf 
{ 
    public class PdfDocumentMerger 
    { 
     private List<string> sourceFileList; 

     #region constructors 

     public PdfDocumentMerger() 
     { 
      //initialize the source file list 
      sourceFileList = new List<string>(); 
     } 

     public PdfDocumentMerger(params string[] fileNames) : this() 
     { 
      sourceFileList.AddRange(fileNames.AsEnumerable<string>()); 
     } 

     #endregion 

     /// <summary> 
     /// Merges multiple PDF documents into one document 
     /// </summary> 
     /// <param name="DestinationFileName">The name and path to the merged document</param> 
     /// <returns>The name and path to the merged document, if successful. Otherwise, the return value is an empty string</returns> 
     public string Merge(string destinationFileName) 
     { 
      try 
      { 
       int sourceIndex = 0; 
       PdfReader reader = new PdfReader(sourceFileList[sourceIndex]); 
       int sourceFilePageCount = reader.NumberOfPages; 

       Document doc = new Document(reader.GetPageSizeWithRotation(1)); 
       PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(destinationFileName, FileMode.Create)); 
       doc.Open(); 

       PdfImportedPage page; 
       PdfContentByte contentByte = writer.DirectContent;     

       int rotation; 
       while (sourceIndex < sourceFileList.Count) 
       { 
        int pageIndex = 0; 
        while (pageIndex < sourceFilePageCount) 
        { 
         pageIndex++; 
         doc.SetPageSize(reader.GetPageSizeWithRotation(pageIndex)); 
         doc.NewPage(); 

         page = writer.GetImportedPage(reader, pageIndex); 
         rotation = reader.GetPageRotation(pageIndex); 

         if (rotation.Equals(90 | 270)) 
          contentByte.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(pageIndex).Height); 
         else 
          contentByte.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);     
        } 

        sourceIndex++; 
        if (sourceIndex < sourceFileList.Count) 
        { 
         reader = new PdfReader(sourceFileList[sourceIndex]); 
         sourceFilePageCount = reader.NumberOfPages; 
        } 
       } 

       doc.Close(); 
      } 
      catch 
      { 
       throw; 
      } 

      return destinationFileName; 
     } 
    } 
}