Solved

iTextSharp resize image

Posted on 2016-09-07
2
49 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
ID: 41789280
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
ID: 41789482
thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I get the id from URL? 19 53
How can I use this extension method? 8 44
Vb.net dynamic formulas in runtime 11 61
Two different visual studio versions 3 21
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

939 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

4 Experts available now in Live!

Get 1:1 Help Now