简体   繁体   English

DevExpress在2页或其他页面上报告不同的水印图像吗?

[英]DevExpress Reports different watermark image on 2 pages or alternative?

I am creating a report with DevExpress in VS2013 and I need to create it according to a template. 我正在VS2013中使用DevExpress创建报告,我需要根据模板创建报告。 The report consists of 2 pages which need to display an image of a page from a PDF en then display data accordingly. 该报告包括2个页面,这些页面需要显示PDF的页面图像,然后相应地显示数据。

In my first attempt I created 2 report with their according watermark images and then added the second report to the first programmatically. 在第一次尝试中,我创建了2个报告及其相应的水印图像,然后以编程方式将第二个报告添加到第一个报告中。

 if (reportModel.Report is RequestBonusPage1)
        {
            var tweedePagina = new RequestBonusPage2();
            secondPage.CreateDocument();
            reportModel.Report.Pages.AddRange(secondPage.Pages);
        }

If I create the report this way the data needed to display on the second page doesn't get passed, hard coded labels are. 如果我以这种方式创建报告,则不会传递需要在第二页上显示的数据,而是硬编码标签。 Also the watermark image itself is not displayed even though I have the DrawWatermark property set to true. 即使将DrawWatermark属性设置为true,也不会显示水印图像本身。

With my second attempt I removed the watermark image from the second page and added the image with a Picturebox but the labels with the data are then displayed next to the picturebox. 第二次尝试,我从第二页上删除了水印图像,并在图像上添加了图片框,但是带有数据的标签随后显示在图片框旁边。 I used this link ( https://www.devexpress.com/Support/Center/Question/Details/Q323059 ) as an example for doing this. 我以该链接( https://www.devexpress.com/Support/Center/Question/Details/Q323059 )为例。

Does anyone how I can make these examples work or know any alternatives as of how to achieve this? 有谁能使这些示例正常工作,或者有其他替代方法可以实现此目的?

If anything is unclear about my explanation don't be afraid to ask. 如果我的解释不清楚,请不要问。

Kind regards 亲切的问候

EDIT: 编辑:

public ActionResult ExportDocumentViewer()
    {
        var reportModel = BuildReportModel(ModelSessionHelper.CurrentReportData);
        ProcessSpecificReport(reportModel);
        return DevExpress.Web.Mvc.DocumentViewerExtension.ExportTo(reportModel.Report);
    }

    private static void ProcessSpecificReport(ReportModel reportModel)
    {
        reportModel.Report.CreateDocument();
        if (reportModel.Report is SalesReport)
        {
            var secondPage = new SalesReportPage2();
            secondPage.CreateDocument();
            reportModel.Report.Pages.AddRange(secondPage.Pages);
        }

        if (reportModel.Report is RequestBonusPage1)
        {
            var secondPage = new RequestBonusPage2();
            secondPage.SetReportData(reportModel.ReportData);
            secondPage.DrawWatermark = true;
            secondPage.CreateDocument();

            reportModel.Report.Pages.AddRange(secondPage.Pages);

            CreateWatermarkRequestBonus(reportModel);
        }
    }

    private static void CreateWatermarkRequestBonus(ReportModel model)
    {
        model.Report.Pages[0].AssignWatermark(new Watermark
        {
            Image = Properties.Resources.bonus_request_page_001,
            ImageViewMode = ImageViewMode.Zoom,
            PageRange = "1",
        });
        model.Report.Pages[1].AssignWatermark(new Watermark
        {
            Image = Properties.Resources.bonus_request_page_002,
            ImageViewMode = ImageViewMode.Zoom,
            PageRange = "2",
        });
    }

You can use Page.AssignWatermark method to set the watermark for particular page. 您可以使用Page.AssignWatermark方法来设置特定页面的水印。
Here is example: 这是示例:

var report = new YourReportClass();

//...

report.CreateDocument();

var page = report.Pages[0];

var watermark = new Watermark();
watermark.Text = "Watermark text";
watermark.TextDirection = DirectionMode.ForwardDiagonal;

page.AssignWatermark(watermark);

report.ShowRibbonPreview();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM