English 中文(简体)
无法在我创建的、利用它制作的pdf上获得图像
原标题:Unable to get image in my pdf created using itextsharp

I am not getting image in pdf i only get text, please help me, i m using iteshsharp 5.2.1 from http://sourceforge.net/projects/itextsharp/

Code of default.aspx.cs

Response.ContentType = "application/pdf";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
savetopdf.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

缺省法典。

<form id="form1" runat="server">
<div id="savetopdf" runat="server">
    <asp:Label ID="lbl" runat="server" Text=" Lorem Ipsum, Dolor"></asp:Label>
    <img src="http://localhost:5583/WebSite1/images/Penguins.jpg" alt="penguins" />
    <img src="http://localhost:5583/WebSite1/images/Tulips.jpg" alt="tulips" />
</div>
</form>
最佳回答
问题回答

努力这样做:

string ImagePath = Server.MapPath("/Images/Printbanner1.jpg");
Document document = new Document();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=xxx.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
document.Open();

iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
htmlTable = htmlTable.ToString().Replace(" ", """);
htmlTable = htmlTable.Replace("px", "");
StringReader sr = new StringReader(htmlTable.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(ImagePath);
pdfDoc.Add(image);
htmlparser.Parse(sr);

pdfDoc.Close();




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签