i m rendering html content of the panel to the pdf with help of itextsharp but i dnt know how to control pdf size and the pdf format is not suitable for print and also By default page zoom is 138% but i need 100%. Can any one help me
my code is here
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=name.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlPrint.RenderControl(hw);
pnlPrint.Style.Add("align", "center");
iTextSharp.text.Image.ALIGN_CENTER.ToString();
// Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
Honnappa
Participant
1112 Points
534 Posts
pdf convertion problem with itexthsarp
Nov 02, 2012 07:26 AM|LINK
i m rendering html content of the panel to the pdf with help of itextsharp but i dnt know how to control pdf size and the pdf format is not suitable for print and also By default page zoom is 138% but i need 100%. Can any one help me
my code is here
Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=name.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); pnlPrint.RenderControl(hw); pnlPrint.Style.Add("align", "center"); iTextSharp.text.Image.ALIGN_CENTER.ToString(); // Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); StringReader sr = new StringReader(sw.ToString()); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End();My Profile
aarsh
Participant
1543 Points
427 Posts
Re: pdf convertion problem with itexthsarp
Nov 02, 2012 07:36 AM|LINK
http://www.codeproject.com/Articles/81118/ITextSharp-Helper-Class
Private Coordinates GetPageAlignment(string PageNumberText, Document document) { Coordinates Coordinates = new PDFLibrary.Coordinates(); try { frmSettings frmsetting = new frmSettings(); PageNumberSize PageNumberSize = frmsetting.GetPageNumberSize(PageNumberText); float TMargin = document.TopMargin; float RMargin = document.RightMargin; float BMargin = document.BottomMargin; float LMargin = document.LeftMargin; setting = new SettingManager(Path.Combine(Application.StartupPath, "settings.ini")); iTextSharp.text.Rectangle pageSize = document.PageSize; string value = setting.Read("Page Number and Formatting", "VerticalAlignment"); switch (value) { case "top": Coordinates.Y = pageSize.Height - (PageNumberSize.Height + TMargin); break; case "middle": Coordinates.Y = (pageSize.Height - (PageNumberSize.Height + TMargin)) / 2; break; case "bottom": Coordinates.Y = BMargin - PageNumberSize.Height; break; } value = setting.Read("Page Number and Formatting", "HorizontalAlignment"); switch (value) { case "left": Coordinates.X = LMargin; break; case "center": Coordinates.X = (pageSize.Width - (PageNumberSize.Width + RMargin)) / 2; break; case "right": Coordinates.X = pageSize.Width - (PageNumberSize.Width + RMargin); break; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return Coordinates; }Honnappa
Participant
1112 Points
534 Posts
Re: pdf convertion problem with itexthsarp
Nov 02, 2012 08:28 AM|LINK
Thanks for reply but Nothing happens with your code..i am using 5.0 version
My Profile