将字符串(字符串是html内容)转换为pdf [英] convert string(string is html content) to pdf

查看:713
本文介绍了将字符串(字符串是html内容)转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面这个编码字符串包含html代码

如何将字符串值用于HtmlTextWriter或StringWriter



string HtmlContent =;

HtmlContent =< html>< body> RAJKUMAR< / body>< / html>;

我可以在此代码下面包含HtmlContent



Response.ContentType =application / pdf;

Response.AddHeader(content-disposition,attachment; filename = Panel.pdf );

Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter (SW);



StringReader sr = new StringReader(sw.ToString());

文件pdfDoc =新文件(PageSize.A4,10f,10f ,100f,0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc,Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(sr);

pdfDoc.Close();

Response.Write(pdfDoc);

Response.End();

In below this coding string contain html code
how to use string value into HtmlTextWriter or StringWriter

string HtmlContent = "";
HtmlContent = "<html><body>RAJKUMAR</body></html>";
where i can include HtmlContent below this code

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

推荐答案

很抱歉没有回答你现在的问题,因为我不明白你的问题是什么。首先,您应该理解它不能是PDF的转换,而只能是HTML呈现的一个特定实例的快照。 PDF和HTML的概念非常不同:HTML流畅灵活,响应用户输入,PDF具有固定渲染,更像是一种电子纸。



现在,我回答了你的最后一篇(在撰写问题的那一刻)已经被一些滥用报告删除了,我的回答是我碰巧发布的。实际上,您的滥用仅仅是未能进行Web搜索并且没有找到GSP,而不是与嵌入在通用Web浏览器中的JavaScript相关的主题。我也报告了这个问题,但后来才意识到这不公平。所以,答案已经丢失​​,但我希望它对你有所帮助。所以,让我在这里发布,即使它违反了网站的规则。

Sorry for not answering your present question, because I don't understand what's your problem. First of all, you should understand that it cannot be a "conversion" to PDF, but only a "snapshot" of one particular instance of HTML rendering. The concepts of PDF and HTML are very different: HTML is fluid and flexible, responds to user input, and PDF has fixed rendering, is more of a kind of electronic paper.

Now, I answered your last (at the moment of writing question) which has been removed by some abuse reports, with my answer which I happened to post. In fact, your "abuse" was merely the failure to do the Web search and figure out that GSP in not the topic relevant to JavaScript embedded in a general-purpose Web browser. I also reported the question but later realized that it wasn't fair. So, the answer is lost, but I hope it can be helpful for you. So, let me post it here, even though it violates the site's rules.
在最后一个(自动删除)问题中, Rajkumar ilamaraja问:
In the last (auto-removed) question, Rajkumar ilamaraja asked:

使用GPS追踪车辆的经纬度

查看更多:ASP.NET jQuery



i想要从我的基于GPS的卡车获取经度和经度,

在我的应用程序中,我想在谷歌地图内显示指向卡车纬度和经度

但我不知道在哪里启动应用程序,我只有用户详细信息。基于用户,显示用户车辆的移动位置

首先,此任务需要什么样的输入。

Track the latitude and longitude for a vehicle using GPS
See more: ASP.NET jQuery

i want to get latitude and longitude from my trucks based GPS,
In my application i want to show inside the google map to point the truck latitude and longitude
But i don't where to start the application, just i have the user details only. Based on the user, to show user vehicle's where it's moving
First of all, What kind of inputs needed for this task.




这是我的答案:

嵌入浏览器中的JavaScript(如果你的jQuery标签是相关的,这就是你正在使用的),因为它具有有限的访问权限本地系统,为安全设置。您只能从标准输入设备处理输入,例如键盘和鼠标/触摸板。您不能使用W3委员会未标准化的任何内容。



但是,标准输入设备和方法的集合趋于快速增长,这是由于快速扩展该设备配备了更新的设备,包括媒体输入(音频和视频),生物识别设备,加速度计,陀螺仪,当然还有GSP。请参阅:

http://dev.w3.org/geo/api /spec-source.html [ ^ ]。



正如您所看到的,这只是规范草案,但许多新标准在正式建立之前在一些主要浏览器中实现标准。



换句话说,你必须为浏览器实现新的输入方法。我甚至不想讨论特定于平台的方法,例如在JavaScript中使用ActiveX组件,这也被认为是完全不安全的,因此它可能会让精通安全的用户拒绝使用您的产品和网站。



请注意,您可以期望在JavaScript中使用GSP来获得更专业的软件托管JavaScript引擎(例如:Chrome OS)。但是你的问题表明你的意思是使用通用的Web浏览器。

JavaScript embedded in a browser (and, if your "jQuery" tag is relevant, this is what you are working with) in has limited access to local system, which is set for security. You can process input only from standardized input devices, such as keyboard and mouse/touchpad. You cannot use anything which is not standardized by the W3 committee.

However, the set of standard input devices and method tends to quickly grow, driven by the quick expansion of the unit equipped with newer devices, which includes media input (audio and video), the use of biometric devices, accelerometers, gyroscopes, and, of course, GSP. Please see:
http://dev.w3.org/geo/api/spec-source.html[^].

As you can see, this is just the draft for the specification, but many new standards get implemented in some major browsers before the establishment of formal standards.

In other words, you have to for the browsers implementing new input methods. I don't even want to discuss platform-specific approaches such as using ActiveX components in JavaScript, which is also considered to be utterly unsafe, so it may cause security-savvy users deny using your products and site.

Note that you can possibly expect the possibility to use GSP in JavaScript for more specialized software hosting JavaScript engine (example: Chrome OS). But your question suggests that you mean the use of general-purpose Web browsers.

-SA


这篇关于将字符串(字符串是html内容)转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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