在后台从 RDLC 报告创建 PDF [英] Creating a PDF from a RDLC Report in the Background

查看:23
本文介绍了在后台从 RDLC 报告创建 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个月末流程,并希望它自动创建一些当时需要创建的报告.我正在使用 rdlc 报告.有没有办法在后台从 RDLC 报告自动创建 PDF?

I am running a month-end process and want to have it automatically create some of the reports that need to be created at that time. I am using rdlc reports. Is there a way to automatically create a PDF from a RDLC report in the background?

推荐答案

这很容易做到,您可以将报告呈现为 PDF,并将生成的字节数组作为 PDF 文件保存在磁盘上.要在后台执行此操作,更多的是您的应用程序是如何编写的问题.您可以启动一个新线程,或使用 BackgroundWorker(如果这是一个 WinForms 应用程序)等.当然,可能存在需要注意的多线程问题.

This is easy to do, you can render the report as a PDF, and save the resulting byte array as a PDF file on disk. To do this in the background, that's more a question of how your app is written. You can just spin up a new thread, or use a BackgroundWorker (if this is a WinForms app), etc. There, of course, may be multithreading issues to be aware of.

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes = reportViewer.LocalReport.Render(
    "PDF", null, out mimeType, out encoding, out filenameExtension,
    out streamids, out warnings);

using (FileStream fs = new FileStream("output.pdf", FileMode.Create))
{
    fs.Write(bytes, 0, bytes.Length);
}

这篇关于在后台从 RDLC 报告创建 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆