从ASP.Net打印PDF而不preVIEW [英] Print PDF from ASP.Net without preview
问题描述
我使用iTextSharp的生成PDF文件,我可以在ASP.Net preVIEW这非常好,但我需要直接发送到打印机,没有一个preVIEW。我希望用户点击打印按钮,并自动打印文档。
I've generated a pdf using iTextSharp and I can preview it very well in ASP.Net but I need to send it directly to printer without a preview. I want the user to click the print button and automatically the document prints.
我知道,一个页面可以直接发送到使用JavaScript window.print(打印机),但我不知道如何使它为PDF。
I know that a page can be sent directly to printer using the javascript window.print() but I don't know how to make it for a PDF.
编辑:它不是嵌入式的,我产生像这样;
it is not embedded, I generate it like this;
...
FileStream stream = new FileStream(Request.PhysicalApplicationPath + "~1.pdf", FileMode.Create);
Document pdf = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(pdf, stream);
pdf.Open();
pdf.Add(new Paragraph(member.ToString()));
pdf.Close();
Response.Redirect("~1.pdf");
...
和我在这里。
推荐答案
最后我做到了,但我不得不使用一个IFRAME,我在ASPX中定义一个IFrame并没有设置src属性,在CS文件我国产生成的PDF文件和设置的iFrame的src属性作为生成的PDF文件名,这样的;
Finally I made it, but I had to use an IFRAME, I defined an IFrame in the aspx and didn't set the src property, in the cs file I made generated the pdf file and set the src property of the iFrame as the generated pdf file name, like this;
Document pdf = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(pdf,
new FileStream(Request.PhysicalApplicationPath + "~1.pdf", FileMode.Create));
pdf.Open();
//This action leads directly to printer dialogue
PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
writer.AddJavaScript(jAction);
pdf.Add(new Paragraph("My first PDF on line"));
pdf.Close();
//Open the pdf in the frame
frame1.Attributes["src"] = "~1.pdf";
和,使得的伎俩,但是,我认为我应该实现您的解决方案斯特凡,问题是,我是新来asp.net和JavaScript,如果我没有一个完整的源$ C $ c口不能code你的建议,但至少是第一步,我感到非常惊讶如何HTML和JavaScript多code,我需要学习。日Thnx。
And that made the trick, however, I think that i should implement your solution Stefan, the problem is that I'm new to asp.net and javascript and if I don't have a complete source code I could not code your suggestion but at least is the first step, I was very surprised how much code in html and javascript i need to learn. Thnx.
这篇关于从ASP.Net打印PDF而不preVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!