Solved

iTextSharp resize image

Posted on 2016-09-07
2
38 Views
Last Modified: 2016-09-08
Hi,

I am trying to use iTextSharp to create PDF from ASP.NET.  The method I am using is to convert to PDF from an ASP.NET panel.  The question I have is how I can resize the image that I load from a db.

Here is my code
ASPX page
<asp:Image ID="ImageAsset" runat="server" Width="100" Height="100"  />

Open in new window


CS page
ImageAsset.ImageUrl = "http://localhost:55589/WebSite1/ResidentialImageStorage/download.jpg";

Open in new window


I can generate PDF but with the image's true size, instead of 100 X 100


The iTextSharp code is as follow  thanks

        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);
        pnlPerson.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 20f, 20f);  //Left, Right, Top, Bottom
        
        //pdfDoc.HtmlStyleClass = "~/css/style.css";
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();

        

        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();

Open in new window

0
Comment
Question by:mcrmg
2 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
Comment Utility
i had no success at all with HTML to PDF , using  a separate CSS file.

I added all the CSS as a style tag in HEAD.  from my working code...
		<title>Documentation Transmittal - ##projid##</title>
		<style type="text/css">
			BODY 				{ font-family: arial; font-size: 12px; }
			#doclist,#dislist 	{ border-collapse: collapse; border: #000000 1px solid; margin-top: 10px;	margin-bottom: 10px; width: 100%; }
			#header TD			{ background-color: silver;	border-bottom: #000000 1px solid; font-weight: bold; padding: 2px; }
			/* vertical text elements   dont work well for output*/
			/* #header .docrev,#header .dociss,#header .distyp { filter: fliph flipv; writing-mode: tb-rl; }
			*/
			.entry TD 			{ border-bottom: silver 1px solid; }
			.entry .docrev 		{ background-color: silver; }
</style>
	</head>
	<body>....

Open in new window

0
 

Author Closing Comment

by:mcrmg
Comment Utility
thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now