如何将带有图像的网页导出到asp.net中的pdf文件 [英] How to export web page with image to pdf file in asp.net

查看:58
本文介绍了如何将带有图像的网页导出到asp.net中的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文本和图像导出到Pdf文件。我使用asp.net图像控件但我无法导出它。我的代码发生异常(找不到图像文件路径而htmlparser无法解析图像URL)。请快速回答我。给我一个方便我怎么做的方法。带有vb代码的asp.net。

我的源代码如下。出现无法找到路径的一部分的错误发生错误:C:\ Images \学生照片\ images10.jpg '

I want to export text and image to Pdf file.I use asp.net image control but I can't export it.My code occur exception(not find image file path and htmlparser cannot parse image URL).Please quickly answer me.Give me a way to convenient me how to do it. asp.net with vb codes.
My source code is following.Unhandle exception error occur as "Could not find a part of the path 'C:\Images\Students Photo\images10.jpg'"

Protected Sub btnReport_Click(sender As Object, e As EventArgs) Handles btnReport.Click
       Using sw As New StringWriter()
           Using hw As New HtmlTextWriter(sw)
               viewReport.RenderControl(hw)
               Dim sr As New StringReader(sw.ToString())
               Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 100.0F, 0.0F)
               Dim htmlparser As New HTMLWorker(pdfDoc)
               PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
               pdfDoc.Open()
               htmlparser.Parse(sr)
               pdfDoc.Close()
               Response.ContentType = "application\pdf"
               Response.AddHeader("content-disposition", "attachment;filename=profile.pdf")
               Response.Write(pdfDoc)
               Response.End()
           End Using
       End Using
   End Sub

推荐答案

以下是将图像徽标添加到pdf中的代码。在应用程序设置中,你必须提到徽标的路径。





string HeaderImagePath = ConfigurationManager.AppSettings [PdfHeader]。ToString( );

iTextSharp.text.Image headerLogo = iTextSharp.text.Image.GetInstance(HeaderImagePath);



headerCell = new PdfPCell(headerLogo) );

headerCell.BorderWidth = 0;

headerCell.Horizo​​ntalAlignment = Element.ALIGN_CENTER;

headerCell.VerticalAlignment = Element.ALIGN_MIDDLE;

tblHeader.AddCell(headerCell);
Here is the code for adding image logo into pdf. in app settings you have to mention the path of logo.


string HeaderImagePath = ConfigurationManager.AppSettings["PdfHeader"].ToString();
iTextSharp.text.Image headerLogo = iTextSharp.text.Image.GetInstance(HeaderImagePath);

headerCell = new PdfPCell(headerLogo);
headerCell.BorderWidth = 0;
headerCell.HorizontalAlignment = Element.ALIGN_CENTER;
headerCell.VerticalAlignment = Element.ALIGN_MIDDLE;
tblHeader.AddCell(headerCell);


最好使用iTextSharp.DLL,它将HTML页面转换成PDF格式。
The best is to use iTextSharp.DLL, which converts HTML pages as it is in PDF format.


这篇关于如何将带有图像的网页导出到asp.net中的pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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