Solved

iTextSharp resize image

Posted on 2016-09-07
2
58 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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