我很擅长在VB2013中开发一个计费程序,该程序需要能够将每个客户账单导出到pdf文件,然后可以将其附加到发送给收费客户的电子邮件中。我已经使用CR多年,但我还没有找到任何方法以编程方式将CR导出为pdf。我已经使activereports2这样做了,但我想回到一个报告生成器。在某些Windows Vista及更高版本的机器上运行时,Datadynamics与Activereports2存在兼容性问题,因此我希望将所有内容都移至CR。
答案 0 :(得分:0)
那么你绝对可以生成Crystal Reports并在.NET中即时转换为PDF。
这里有一些示例代码可以帮助解决这个问题(这会将PDF保存到数据库中,但如果您不需要,可以删除该部分):
public static int Crystal_PDFToDatabase(string reportName, object par1, object par2, object par3, string user, string DocName, string DocDesc, string DocType, int ClaimID, string exportFormatType)
{
try
{
CrystalReportSource CrystalReportSource1 = Crystal_SetDataSource(reportName, par1, par2, par3);
//SET EXPORT FORMAT
CrystalDecisions.Shared.ExportFormatType typ = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
Stream str = CrystalReportSource1.ReportDocument.ExportToStream(typ);
if (str != null)
{
var memoryStream = new MemoryStream();
str.CopyTo(memoryStream);
int DocID = db_Docs.SaveNewDocument(DocName, DocDesc, DocType, user, memoryStream.ToArray(), ClaimID, null, null);
return DocID;
}
//clear out cache (to prevent other crystal reports from reusing old generated documents
CrystalReportSource1.ReportDocument.Close();
CrystalReportSource1.Dispose();
return 0;
}
catch
{
return 0;
}
}
现在,单独的问题不会为报告中的每个页面生成单独的PDF。我根本就不会这样设计。我反而让Crystal报告生成1页,即时转换为PDF内存流,然后通过电子邮件发送出去。然后迭代到下一个客户。这样更容易,而不必弄清楚如何(如果可能的话)将一个巨大的Crystal Report / PDF分成多个切片。