2011-10-07 86 views
2

有沒有辦法通過將許多rdlc報告合併爲一個大型的pdf在.net框架中來創建報告書。 通常我們通過Datasource生成pdf到rdlc報告,然後我們將它轉​​換成pdf格式。所以,雖然渲染可以合併多個rdlc生成的PDF文件? 是否有任何工具可用於合併使用SSRS生成的PDF(SQL Server Reporting Service)。合併使用SSRS和ASP.NET生成的PDF格式報告

回答

0

我已成功使用http://khsw.blogspot.com/2006/04/merge-pdf-files-using-itextsharp.html的代碼將多個現有PDF合併到單個文檔中。

+0

以上要求PDF是物理存在和合並。如果我們使用將本地報告呈現爲pdf的字節流合併並且呈現爲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; 
     } 
    } 
}