Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

iTextSharp resize image

Posted on 2016-09-07
2
Medium Priority
?
94 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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