C# 使用SSRS和ASP.NET合并Pdf格式生成的报告
有没有一种方法可以通过在.net framework中将许多rdlc报告合并到一个大型pdf中来创建报告集。 通常我们将数据源传递给rdlc报告生成pdf,然后将其呈现为pdf格式。那么,在渲染时,我们可以合并多个rdlc生成的PDF吗?C# 使用SSRS和ASP.NET合并Pdf格式生成的报告,c#,asp.net,reporting-services,ssrs-2008,C#,Asp.net,Reporting Services,Ssrs 2008,有没有一种方法可以通过在.net framework中将许多rdlc报告合并到一个大型pdf中来创建报告集。 通常我们将数据源传递给rdlc报告生成pdf,然后将其呈现为pdf格式。那么,在渲染时,我们可以合并多个rdlc生成的PDF吗? 是否有任何工具可以合并使用SSRS(SQL Server Reporting Service)生成的PDF 我已成功使用处的代码将多个现有PDF合并到单个文档中。我已成功使用处的代码将多个现有PDF合并到单个文档中。我知道您可以将PDF与iTextSharp合
是否有任何工具可以合并使用SSRS(SQL Server Reporting Service)生成的PDF 我已成功使用处的代码将多个现有PDF合并到单个文档中。我已成功使用处的代码将多个现有PDF合并到单个文档中。我知道您可以将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;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.IO;
使用iTextSharp.text;
使用iTextSharp.text.pdf;
名称空间组件.Pdf
{
公共类PDF文档合并
{
私有列表源文件列表;
#区域构造函数
公共PDF文档合并()
{
//初始化源文件列表
sourceFileList=新列表();
}
公共PDFDocumentMerge(参数字符串[]文件名):this()
{
sourceFileList.AddRange(fileNames.AsEnumerable());
}
#端区
///
///将多个PDF文档合并到一个文档中
///
///合并文档的名称和路径
///合并文档的名称和路径(如果成功)。否则,返回值为空字符串
公共字符串合并(字符串destinationFileName)
{
尝试
{
int sourceIndex=0;
PdfReader reader=新的PdfReader(sourceFileList[sourceIndex]);
int sourceFilePageCount=reader.NumberOfPages;
Document doc=新文档(reader.GetPageSizeWithRotation(1));
PdfWriter writer=PdfWriter.GetInstance(doc,新文件流(destinationFileName,FileMode.Create));
doc.Open();
PDF导入页面;
PdfContentByte contentByte=writer.DirectContent;
整数旋转;
while(sourceIndex
我知道您可以将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;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.IO;
使用iTextSharp.text;
使用iTextSharp.text.pdf;
名称空间组件.Pdf
{
公共类PDF文档合并
{
私有列表源文件列表;
#区域构造函数
公共PDF文档合并()
{
//初始化源文件列表
sourceFileList=新列表();
}
公共PDFDocumentMerge(参数字符串[]文件名):this()
{
sourceFileList.AddRange(fileNames.AsEnumerable());
}
#端区
///
///将多个PDF文档合并到一个文档中
///
///合并文档的名称和路径
///合并文档的名称和路径(如果成功)。否则,返回值为空字符串
公共字符串合并(字符串destinationFileName)
{
尝试
{
int sourceIndex=0;
PdfReader reader=新的PdfReader(sourceFileList[sourceIndex]);
int sourceFilePageCount=reader.NumberOfPages;
Document doc=新文档(reader.GetPageSizeWithRotation(1));
PdfWriter writer=PdfWriter.GetInstance(doc,新文件流(destinationFileName,FileMode.Create));
doc.Open();
PDF导入页面;
PdfContentByte contentByte=writer.DirectContent;
整数旋转;
while(sourceIndex