在运行时将aspx页面转换为pdf文件 [英] Convert aspx page into pdf file at runtime

查看:137
本文介绍了在运行时将aspx页面转换为pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时将ASPX页面转换为PDF文件?

我已经尝试了不同的代码但是没有为我工作?PLZ帮助我,与ITEXTSHARP一起试用,PDF文件是虽然只能使用静态控件,但是像HTML设计部分那样创建了标签,面板等。不能在文本框中动态输入文本并在PDF文件中显示。

PLZ帮助我了解这个.THANKS IN ADVANCE。

HOW TO CONVERT ASPX PAGE INTO PDF FILE AT RUNTIME?
I HAVE TRIED DIFFERENT CODES BUT NONE OF THEM IS WORKING OUT FOR ME?PLZ HELP ME OUT,TRIED WITH ITEXTSHARP,A PDF FILE IS GETTING CREATED BUT ONLY WITH STATIC CONTROLS LIKE LABELS,PANELS ETC CREATED DURING HTML DESIGN PART.AM NOT ABLE TO ENTER TEXT DYNAMICALLY IN TEXTBOX AND DISPLAY IN PDF FILE.
PLZ HELP ME OUT WITH THIS.THANKS IN ADVANCE.

推荐答案

您需要使用PDFSharp中的MigraDoc来将HTML呈现为PDF。链接: http://www.pdfsharp.com/ [ ^ ]



现在要创建包含服务器端控件的HTML输出,你需要什么do,将整个页面代码放在一个用户控件中,并按照链接在运行时生成HTML,这将生成输出html,然后您需要将其输入MigraDoc以创建PDF文档。



you need to use something like MigraDoc from PDFSharp to render HTML to PDF. LINK: http://www.pdfsharp.com/[^]

And now to create the HTML output including server side controls, what u need to do is, put the whole pages codes inside a single user control and follow the link to generate the HTML on runtime which will produce the output html which you need to then feed to the MigraDoc to create the PDF document.

StringBuilder SB = new StringBuilder();
StringWriter SW = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
UCDummy.Visible = true;
UCDummy.RenderControl(htmlTW);
WhereEverIWantItToGo = SB.ToString();
UCDummy.Visible = false;





http://www.velocityreviews.com/forums/t104419-render-and-get -html-from-usercontrol.html [ ^ ]



之前我使用过这种技术,但现在找不到代码片段。如果你需要,给我发电子邮件,我将不得不做一些挖掘。



----------------- ----------新代码示例---------------------



假设您想渲染整个aspx页面并获取html字符串中的输出,然后您可以将其推送到pdf生成器:





http://www.velocityreviews.com/forums/t104419-render-and-get-html-from-usercontrol.html[^]

I have used this technique before, but can't find the code snippet now. Send me an email if u need it, i will have to do some digging.

--------------------------- NEW CODE SAMPLE ---------------------

let say u want to render the whole aspx page and get the output in html string which u can then push it to pdf generator:

System.Text.StringBuilder sb = new StringBuilder();
System.IO.StringWriter tw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter ht = new HtmlTextWriter(tw);
this.RenderControl(ht);				
string body = sb.ToString();





就像小费..在做这个之前......你可能想要如果你不需要它们,请关闭你的页眉和页脚控件。这也很容易,在调用RenderControl之前,将这些控件的可见性隐藏起来。



这里的主要关键是this.RenderControl,它接受一个HtmlTextWriter。 br />


希望这会有所帮助。



谢谢..



just as a tip.. before doing this.. u might want to turn off ur header and footer controls if u don't need them. That is also easy to do, just before calling RenderControl, make those controls visibility to hidden.

The main key here is the this.RenderControl which takes a HtmlTextWriter.

Hope this helps.

Thanks..


这篇关于在运行时将aspx页面转换为pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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