将两个或多个 Crystal Reports 合并为一个 PDF

发布于 2024-10-15 15:12:08 字数 1449 浏览 8 评论 0原文

我有一个复选框列表。如果我选择两个或多个值,则 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‘画卷フ 2024-10-22 15:12:08

Crystal Reports 旨在为每条记录生成一页。您只需设置一个包含多行数据的数据源,为您的报告设置该数据源并将其直接导出为 pdf(已“合并”)。

首先,您必须使用您的数据创建一个数据源。例如,您可以使用 Visual Studio 设计器创建数据集。更多信息请此处

然后您必须设置水晶报表的数据源。您可以使用 Crystal 设计器来完成。

然后在运行时,您只需使用与所有选定复选框相关的数据填充 rpt,并将其导出为 pdf。在 .rpt 文件内,在与复选框相关的特定列上创建一个组,并在该组上设置“分页符”选项。这将生成一个包含所有记录的 Pdf 文件,每页 1 个。

下面是示例代码:

            using (var reportDocument = new ReportDocument())
        {
            var datasource = new Datasource { EnforceConstraints = false };

            var adapter = new adoTableAdapter { Connection = ConfigurationManager.ConnectionStrings["ConnectionString"]) };
            adapter.Fill(datasource.ado);

            reportDocument.Load(RptPath);
            reportDocument.SetDataSource(datasource);

            PageMargins myMargins = reportDocument.PrintOptions.PageMargins;
            myMargins.topMargin = Settings.Default.DefaultTopMargin;
            myMargins.leftMargin = Settings.Default.DefaultLeftMargin;
            reportDocument.PrintOptions.ApplyPageMargins(myMargins);
            reportDocument.PrintOptions.PaperSize = PaperSize.PaperA5;
            reportDocument.PrintOptions.PaperOrientation = PaperOrientation.Landscape;

            reportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            reportDocument.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            reportDocument.ExportOptions.DestinationOptions = new DiskFileDestinationOptions { DiskFileName = PdfFilename };
            reportDocument.ExportOptions.FormatOptions = new PdfRtfWordFormatOptions();

            reportDocument.Export();
        }

在此代码中,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:

            using (var reportDocument = new ReportDocument())
        {
            var datasource = new Datasource { EnforceConstraints = false };

            var adapter = new adoTableAdapter { Connection = ConfigurationManager.ConnectionStrings["ConnectionString"]) };
            adapter.Fill(datasource.ado);

            reportDocument.Load(RptPath);
            reportDocument.SetDataSource(datasource);

            PageMargins myMargins = reportDocument.PrintOptions.PageMargins;
            myMargins.topMargin = Settings.Default.DefaultTopMargin;
            myMargins.leftMargin = Settings.Default.DefaultLeftMargin;
            reportDocument.PrintOptions.ApplyPageMargins(myMargins);
            reportDocument.PrintOptions.PaperSize = PaperSize.PaperA5;
            reportDocument.PrintOptions.PaperOrientation = PaperOrientation.Landscape;

            reportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            reportDocument.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            reportDocument.ExportOptions.DestinationOptions = new DiskFileDestinationOptions { DiskFileName = PdfFilename };
            reportDocument.ExportOptions.FormatOptions = new PdfRtfWordFormatOptions();

            reportDocument.Export();
        }

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.

夏末的微笑 2024-10-22 15:12:08

坏消息:.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 instead ExportToHttpResponse 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

嘴硬脾气大 2024-10-22 15:12:08

水晶做不到这一点。但是,您可以将 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

彼岸花ソ最美的依靠 2024-10-22 15:12:08

您可以使用 Atalasoft dotImage 来完成此操作(免责声明 - 我在 Atalasoft 工作并编写了大部分 PDF 工具,包括这个)。事实上,它实际上只是一句简单的话:

PdfDocument.Combine(outputFile, intputFile1, intputFile2, ...);  // the signature uses params string[]

有些风格可以与流或路径一起使用,并且如果需要,您可以加密输出。

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:

PdfDocument.Combine(outputFile, intputFile1, intputFile2, ...);  // the signature uses params string[]

There are flavors that work with Streams or paths, and you can encrypt the output if you need to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文