将两个或多个 Crystal Reports 合并为一个 PDF
我有一个复选框列表。如果我选择两个或多个值,则 CheckBoxList SelectedValues 将作为参数一一传递,并且我想为每个 SelectedValue 生成 PDF 格式的 Crystal Report,并且我想将所有 Crystal Report PDF 格式合并为单个 PDF格式。如何实现这一目标? 到目前为止,我只生成了一个 PDF 格式的 Crystal Report。 在下面,我给出了关于如何生成 PDF 格式的水晶报表的代码。
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
string[] str = conn.Split(';');
string server = str[0].Substring(str[0].IndexOf(" = ") + 3);
string database = str[1].Substring(str[1].IndexOf(" = ") + 3);
string userid = str[2].Substring(str[2].IndexOf(" = ") + 3);
string password = "Welc0me";//str[3].Substring(str[3].IndexOf(" = ") + 3);
rpt.Load(Server.MapPath(RepPath));
for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
{
rpt.DataSourceConnections[i].SetConnection(server, database, userid, password);
}
// Here ReleaseID will be replaced by the CheckBoxList's SelectedValue
rpt.SetParameterValue(0, ReleaseID);
rpt.SetParameterValue(1, false);
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
HttpContext.Current.Response, true, "Docs Report");
但上面的代码只是一次生成一个pdf报告。但我想将每个 CheckBoxList 选定值作为参数传递。例如,如果我选择了三个值,那么Crystal Report应该一一包含所有三个Crystal Report对应的SelectedValue。 如何将所有 PDF Crystal Report 合并为单个 Crystal Report。我必须解决这个问题。请帮我。
I have a CheckBoxList. If I select two or more values then the CheckBoxList SelectedValues would be passed as a Parameter one by one, and I want to generate the Crystal Report for each SelectedValue in PDF format and I want to merge all the Crystal Report PDF format into a Single PDF format. How to achieve this?
So far I have generated only a single Crystal Report in PDF format.
In below, I have given the Code about How I had generated the Crystal Report in PDF Format.
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
string[] str = conn.Split(';');
string server = str[0].Substring(str[0].IndexOf(" = ") + 3);
string database = str[1].Substring(str[1].IndexOf(" = ") + 3);
string userid = str[2].Substring(str[2].IndexOf(" = ") + 3);
string password = "Welc0me";//str[3].Substring(str[3].IndexOf(" = ") + 3);
rpt.Load(Server.MapPath(RepPath));
for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
{
rpt.DataSourceConnections[i].SetConnection(server, database, userid, password);
}
// Here ReleaseID will be replaced by the CheckBoxList's SelectedValue
rpt.SetParameterValue(0, ReleaseID);
rpt.SetParameterValue(1, false);
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
HttpContext.Current.Response, true, "Docs Report");
But the above code is only to generate a single pdf report at a time. But I want to pass each CheckBoxList selectedvalue as a Parameter. For Example, If I Selected three values means, then the Crystal Report should contain all the three Crystal Report for the Corresponding SelectedValue one by one.
How do I merge all the PDF Crystal Report into a Single Crystal Report. I have to solve this problem. Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Crystal Reports 旨在为每条记录生成一页。您只需设置一个包含多行数据的数据源,为您的报告设置该数据源并将其直接导出为 pdf(已“合并”)。
首先,您必须使用您的数据创建一个数据源。例如,您可以使用 Visual Studio 设计器创建数据集。更多信息请此处。
然后您必须设置水晶报表的数据源。您可以使用 Crystal 设计器来完成。
然后在运行时,您只需使用与所有选定复选框相关的数据填充 rpt,并将其导出为 pdf。在 .rpt 文件内,在与复选框相关的特定列上创建一个组,并在该组上设置“分页符”选项。这将生成一个包含所有记录的 Pdf 文件,每页 1 个。
下面是示例代码:
在此代码中,dsEtiqueta 是 ADO 数据源,RptPath 是 *.rpt 报告文件的路径,pdf 文件名是使用 timeSpan 生成的。这是我的项目中所需要的,但请随意调整它以满足您的需求。
编辑:用 VS 2010 的 CR 完成。
Crystal Reports are meant to generate one page per record. You just have to set a datasource with several lines of data, set that data source for your report and export it to pdf directly (already "merged").
First of all you have to create a datasource with your data. For instance, you can create a DataSet using the Visual Studio designer. More info here.
Then you have to set the data source for your Crystal Report. You can do it with the Crystal designer.
Then at runtime, you just have to populate the rpt with the data related to all selected checkboxes, and export it to pdf. Inside the .rpt file create a group on the specific column related to the checkboxes with the "page break after" option set on the group. This will generate one Pdf file containing all your records, 1 per page.
Here's a sample code:
In this code, dsEtiqueta is the ADO datasource, RptPath the path to the *.rpt report file and the pdf filename is generated using a timeSpan. It's what I needed in my project but feel free to adapt it to your needs.
Edit: done with CR for VS 2010.
坏消息:.Net 和 Crystal 都不支持合并 PDF。
好消息:
使用
ExportToStream
而不是ExportToHttpResponse
将每个报告写入其自己的内存流。然后使用第三方库将两个 PDF 合并为一个 PDF。以下是一些开源库: http://csharp-source.net/open-source/ pdf 库。也有许多商业库可用,其中之一是 DynamicPDF
Bad news: Neither .Net nor Crystal has support to merge PDFs.
Good News:
Use
ExportToStream
insteadExportToHttpResponse
to write each report to its own memory stream. Then use a 3rd party library to merge the two PDFs into a single one.Here are some open source libraries: http://csharp-source.net/open-source/pdf-libraries. There are many commercial libraries available too, one is DynamicPDF
水晶做不到这一点。但是,您可以将 Crystal 导出到内存流,然后您可以使用此站点来学习如何合并它们: http://www.codeproject.com/KB/files/SimplePdfMerger.aspx
Crystal cannot do this. You can however make Crystal export to a memory stream, then you can use this site to learn how to merge them: http://www.codeproject.com/KB/files/SimplePdfMerger.aspx
您可以使用 Atalasoft dotImage 来完成此操作(免责声明 - 我在 Atalasoft 工作并编写了大部分 PDF 工具,包括这个)。事实上,它实际上只是一句简单的话:
有些风格可以与流或路径一起使用,并且如果需要,您可以加密输出。
You can do this with Atalasoft dotImage (disclaimer - I work for Atalasoft and wrote most of the PDF tools, including this one). In fact, it literally is a one-liner:
There are flavors that work with Streams or paths, and you can encrypt the output if you need to.