Breaking News

Editors Picks

Friday, December 16, 2011

Export fusion charts as images and add to pdf file with text


Export fusion charts as images and add to pdf file with text

string fileName = "fusionchart/pdf.png";
ServerSideImageHandler ssh = new ServerSideImageHandler(Server.MapPath("fusionchart/MSCombi2D.swf"), 500, 400, "", Server.MapPath("xmlschemas/XmlData.xml"), Server.MapPath(fileName));
ssh.BeginCapture();
string pdfpath = Server.MapPath("fusionchart/FusionCharts.pdf");
string imagepath = Server.MapPath("fusionchart/pdf.png");
Document doc = new Document();
try
{
PdfWriter.GetInstance(doc, new FileStream(pdfpath, FileMode.Create));
doc.Open();
doc.Add(new Paragraph("GIF"));
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(imagepath);
doc.Add(gif);
}
catch (DocumentException dex)
{
Response.Write(dex.Message);
}
catch (IOException ioex)
{
Response.Write(ioex.Message);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
doc.Close();
}
Read more ...

insert text and image in an existing PDF form template using iTextSharp


 first download iTextSharp.dll and add reference to ur application

protected void Page_Load(object sender, EventArgs e)
{
string fileName = "Report/pdf.png";
string pdfpath = Server.MapPath("Report/Summary.pdf");
string imagepath = Server.MapPath("Report/pdf.png");


string pdfTemplate = Server.MapPath("Report\\Report.pdf");//@"C:\Report.pdf";
string imagePath = String.Empty;
PdfReader pdfReader = null;
// Create the form filler
FileStream pdfOutputFile = new FileStream(pdfTemplate, FileMode.Create);
pdfReader = new PdfReader(Server.MapPath("Report\\Summary.pdf"));//"C:\\Template.pdf"
PdfStamper pdfStamper = null;
pdfStamper = new PdfStamper(pdfReader, pdfOutputFile);
// Get the form fields
AcroFields testForm = pdfStamper.AcroFields;
sql = "select ReciId,FEASIBILITYID,FEASIBILITY_DATE,CUSTOMER_NAME,CUSTOMER_ADDRESS  from ovlfeasibility_report where  FEASIBILITYID='" + FSID + "'";
b.fetchdata(sql,out dt_feasibility);
testForm.SetField("txtDate", DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() + " " + DateTime.Now.ToLocalTime().ToString().Split(' ')[0] + " " + DateTime.Now.ToLocalTime().ToString().Split(' ')[1]);
if (dt_feasibility.Rows.Count > 0)
{
testForm.SetField("txtRID", dt_feasibility.Rows[0]["ReciId"].ToString());
testForm.SetField("txtFID", dt_feasibility.Rows[0]["FEASIBILITYID"].ToString());
testForm.SetField("txtCustName", dt_feasibility.Rows[0]["Customer_Name"].ToString());
testForm.SetField("txtCustAddress", dt_feasibility.Rows[0]["Customer_Address"].ToString());
testForm.SetField("imgchart", imagepath);
iTextSharp.text.Image instanceImg = iTextSharp.text.Image.GetInstance(imagepath);
PdfContentByte overContent = pdfStamper.GetOverContent(1);
float[] imageArea = testForm.GetFieldPositions("imgchart");
iTextSharp.text.Rectangle imageRect = new Rectangle(imageArea[1], imageArea[2], imageArea[3], imageArea[4]);
instanceImg.ScaleToFit( 600, 270);
instanceImg.SetAbsolutePosition(-10, 20);
overContent.AddImage(instanceImg);

overContent = null;

}
//PdfContentByte overContent = pdfStamper.GetOverContent(1);
pdfStamper.FormFlattening = true;
pdfStamper.Close();
pdfReader.Close();

//----start----Disposing Object--------
pdfReader = null;
pdfOutputFile.Dispose();
pdfOutputFile = null;
pdfStamper = null;
testForm = null;

//----end------Disposing Object--------
b = null;
dt_feasibility.Dispose();
dt_feasibility = null;

Response.Clear();
string strpdfpath2 = Server.MapPath("Report\\Report.pdf");  //@"C:/Report.pdf";
Response.ContentType = "text/pdf";
Response.AppendHeader("Content-Disposition", "attachment;filename=Report.pdf");
Response.TransmitFile(strpdfpath2);
//Directory.Delete("C:\\PDF1",true);
Response.End();
}
Read more ...

Contact Us

Name

Email *

Message *