我有一份有两页的水晶报告;一个在肖像中,另一个在横向格式中。在报告中它看起来很好但是当我将它导出为PDF时,两个页面都以纵向格式导出而丢失了一些数据。谁能解决我的问题?非常感谢提前。
答案 0 :(得分:4)
如果您使用的是ExportToStream,那有点棘手,因为主要的公共场所是
report.ExportToStream(ExportFormatType formatType)
忽略FormatOptions。相反,您需要使用
report.FormatEngine.ExportToStream(ExportRequestContext reqContext)
此代码应该做你想要的(使用PdfSharp组合):
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
...
using (var report = new ReportClass { FileName = Server.MapPath("/Crystal/Reports/DosBatches.rpt") })
{
report.Load();
/* set data source connections */
/* set parameters */
// export the first page
report.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
var exportOptions1 = new ExportOptions
{
ExportFormatType = ExportFormatType.PortableDocFormat,
FormatOptions = new PdfFormatOptions { UsePageRange = true, FirstPageNumber = 1, LastPageNumber = 1 }
};
exportRequestContext.ExportInfo = exportOptions1;
var stream1 = report.FormatEngine.ExportToStream(exportRequestContext);
stream1.Seek(0, SeekOrigin.Begin);
// export the second page
report.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
var exportOptions2 = new ExportOptions
{
ExportFormatType = ExportFormatType.PortableDocFormat,
FormatOptions = new PdfFormatOptions { UsePageRange = true, FirstPageNumber = 2, LastPageNumber = 2 }
};
exportRequestContext.ExportInfo = exportOptions2;
var stream2 = report.FormatEngine.ExportToStream(exportRequestContext);
stream2.Seek(0, SeekOrigin.Begin);
// merge the two PDF streams
var combinedPdf = new PdfDocument();
foreach (PdfPage page in PdfReader.Open(stream1, PdfDocumentOpenMode.Import).Pages)
combinedPdf.AddPage(page);
foreach (PdfPage page in PdfReader.Open(stream2, PdfDocumentOpenMode.Import).Pages)
combinedPdf.AddPage(page);
// probably not the most efficient, but works
var output = new MemoryStream();
combinedPdf.Save(output, false);
return new FileStreamResult(output, "application/pdf");
}
答案 1 :(得分:1)
按照这个简单的步骤,不需要执行任何单行代码 步骤: