如何在离线时使用C#将Div区域转换为Pdf和Excel格式 [英] How Do I Convert Div Region Into Pdf And Excel Format Using C# In Offline

查看:110
本文介绍了如何在离线时使用C#将Div区域转换为Pdf和Excel格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在离线状态下使用c#将div区域转换为pdf和excel格式

我想将div区域数据打印为pdf格式

任何人都可以帮助我

解决方案

Chk this链接:





http://stackoverflow.com/questions/19090540/export-div-content-to -a-pdf-file-using-javascript [ ^ ]



http://parall.ax/products/jspdf [ ^ ]



http://www.aspsnippets.com/Articles/Export-HTML-DIV-conte nts-to-PDF-using-iTextSharp-in-ASPNet.aspx [ ^ ]



将包含图像的网页导出为PDF [ ^ ]



http://www.c -sharpcorner.com/UploadFile/raj1979/export-div-content-to-pdf-using-itextsharp/ [ ^ ]


您可以使用iTextSharp生成PDF文件。使用包管理器进行安装。

https://www.nuget.org/packages/itextsharp/ [ ^ ]



 <   div     id   =  MyDiv      runat   = 服务器 >  
< p > div content < / p >
< / div >



,例如按钮点击事件:

  protected   void  btnExport_Click( object  sender,EventArgs e)
{
Response.ContentType = application / pdf;
Response.AddHeader( content-disposition attachment; filename = div.pdf);
Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
MyDiv.RenderControl(htmlTextWriter);

StringReader stringReader = new StringReader(stringWriter.ToString());
Document Doc = new 文档(PageSize.A4,10f,10f,100f,0f);
HTMLWorker htmlparser = new HTMLWorker(Doc);
PdfWriter.GetInstance(Doc,Response.OutputStream);

Doc.Open();
htmlparser.Parse(stringReader);
Doc.Close();
Response.Write(Doc);
Response.End();
}



您需要使用c#代码顶部的语句添加以下内容



 使用 iTextSharp.text; 
使用 iTextSharp.text.pdf;
使用 iTextSharp.text.html;
使用 iTextSharp.text.html.simpleparser;


how do i convert div region into pdf and excel format using c# in offline
I want to print the div region data as pdf format
Would Any one help me

解决方案

Chk this Links :


http://stackoverflow.com/questions/19090540/export-div-content-to-a-pdf-file-using-javascript[^]

http://parall.ax/products/jspdf[^]

http://www.aspsnippets.com/Articles/Export-HTML-DIV-contents-to-PDF-using-iTextSharp-in-ASPNet.aspx[^]

Export web page with images to PDF[^]

http://www.c-sharpcorner.com/UploadFile/raj1979/export-div-content-to-pdf-using-itextsharp/[^]


you can use iTextSharp to generate PDF file. use package manager to install it.
https://www.nuget.org/packages/itextsharp/[^]

<div id="MyDiv"  runat="server">
<p>div content</p>
</div>



in your code, for example button click event:

protected void btnExport_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=div.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
   
    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
    MyDiv.RenderControl(htmlTextWriter);
   
    StringReader stringReader = new StringReader(stringWriter.ToString());
    Document Doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(Doc);
    PdfWriter.GetInstance(Doc, Response.OutputStream);
   
    Doc.Open();
    htmlparser.Parse(stringReader);
    Doc.Close();
    Response.Write(Doc);
    Response.End();
}


you need to add below using statements at the top of your c# code

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;


这篇关于如何在离线时使用C#将Div区域转换为Pdf和Excel格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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