greeny_1984 14 Posting Whiz

Hi everyone,


I have a requirement where I need to generate a pdf doc.I am using itextlibrary for that condition.I am able to generate pdf doc but alignment is not correct.The table is getting divided in to two equal parts in pdf doc for what ever width I specify.How to set the table

at desired location in pdf doc and set width of columns.I tried to set width of column in the html table but its not working.Please suggest some solution to this problem.

StringBuilder strHTMLContent = new StringBuilder();

strHTMLContent.Append("<table style='font-family:Times New Roman; font-size:18px;'>".ToString());

strHTMLContent.Append("<tr><td width='100px'>column1</td><td width='300px'>column2</td></tr>");

strHTMLContent.Append("</table>");
//Rectangle Ret = new Rectangle(1f, 1f, 1f, 1f);
Document doc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);


try
{

PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath + @"\Columns1.pdf", FileMode.Create));

doc.Open();




HTMLWorker htmlWorker = new HTMLWorker(doc);

htmlWorker.Parse(new StringReader(strHTMLContent.ToString()));


doc.Close();
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=\" Columns1.pdf\"");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.WriteFile(MapPath("~/Columns1.pdf"));
}
catch( Exception ex)
{
Response.Write(ex.Message.ToString());
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.