Link to home
Create AccountLog in
Avatar of mcrmg
mcrmg

asked on

iTextSharp resize image

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

ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of mcrmg
mcrmg

ASKER

thank you