简体   繁体   English

单击按钮将aspx页面打印为PDF,但在服务器端打印PDF

[英]Print aspx page to PDF on button click, but print PDF serverside

I have a report that's displayed on a webpage, and the users have been printing this webpage to PDF. 我有一个显示在网页上的报告,并且用户已将该网页打印为PDF。 What I need is for the webpage to automatically print to PDF (save) to a location on the websites server when user clicks a button. 我需要的是,当用户单击按钮时,网页可以自动打印为PDF(保存)到网站服务器上的某个位置。

iTextSharp doesn't seem to let me just save the PDF exactly how it looks when you Print To PDF (keeping css etc), also there's some licencing complications. iTextSharp似乎并不能让我完全按照打印到PDF时的样子保存PDF(保留CSS等),还存在一些许可问题。 PrinceXML looks good but is way too expensive. PrinceXML看起来不错,但是太贵了。

Is there no way to open a new aspx page and then print it to PDF server side? 有没有办法打开新的aspx页面,然后将其打印到PDF服务器端?

You can use the built-in RLDC report. 您可以使用内置的RLDC报告。 It's free, has a nice design and features, and allows you to print to PDF. 它是免费的,具有漂亮的设计和功能,并允许您打印到PDF。 You don't need to save a PDF file and worry about managing and deleting it, simply print it to a stream and use the stream to download. 您无需保存PDF文件,而不必担心管理和删除它,只需将其打印到流中并使用该流进行下载。

Something like this: 像这样:

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

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

And then write bytes to the download stream. 然后将bytes写入下载流。

Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= filename" + "." + extension);
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.Flush();
Response.End();

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

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