我找不到从报告查看器打印报告的任何其他方法,所以做了一些谷歌搜索,发现 itext 清晰,所以首先我生成报告,然后在源文件中创建一个 pdf,然后我点击打印按钮,它打印了刚刚的 pdf通过在客户端机器上调出 pdf 的打印选项创建,但我遇到的问题是当多个用户生成报告并打印 pdf 时,他们收到错误消息,指出资源已在使用中,请告诉我如果有解决此问题的方法或我可以在客户端计算机上打印报告的任何其他方式?
我用来打印的代码
using iTextSharp.text.pdf;
using iTextSharp.text;
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType,
out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("output.pdf"),
FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
//Open existing PDF
Document document = new Document(PageSize.LETTER);
PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("output.pdf"));
//Getting a instance of new PDF writer
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(
HttpContext.Current.Server.MapPath("Print.pdf"), FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
int i = 0;
int p = 0;
int n = reader.NumberOfPages;
Rectangle psize = reader.GetPageSize(1);
float width = psize.Width;
float height = psize.Height;
//Add Page to new document
while (i < n)
{
document.NewPage();
p++;
i++;
PdfImportedPage page1 = writer.GetImportedPage(reader, i);
cb.AddTemplate(page1, 0, 0);
}
//Attach javascript to the document
PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
writer.AddJavaScript(jAction);
document.Close();
//Attach pdf to the iframe
frmPrint.Attributes["src"] = "Print.pdf";
有没有其他更快的方法可以使用外部按钮从报表查看器打印报表?