Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

how to make my paragraph align center with image immediately to it's right in pdf report from c# windows forms using itextsharp

csharp sql server 2008 itextsharp

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 mcleane

mcleane

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 16 April 2014 - 02:10 AM

hi my name is vishal. For past 10 days i have breaking my head on doing some modifications in my pdf report from c# windows forms with sql server data and with iTextSharp.

 

First i was able to export datas from sql server tables to pdf report through c# code given below:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Data;
 using System.IO;
using System.Data.SqlClient;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Diagnostics;
namespace DRRS_CSharp
{
    public partial class frmPDFTechnician : Form
    {
        public frmExcelTechnician()
        {
            InitializeComponent();
        }
 private void btnExport_Click(object sender, EventArgs e)
        {
                Document doc = new Document(PageSize.A4.Rotate());
                var writer=  PdfWriter.GetInstance(doc, new FileStream("Technician22.pdf", FileMode.Create));
                doc.SetMargins(50, 50, 50, 50);
                doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
                doc.Open();
                 PdfPTable table = new PdfPTable(7);
                table.TotalWidth=585f;
                table.LockedWidth = true;
                PdfPCell cell=new PdfPCell(new Phrase("Institute/Hospital:AIIMS,NEW DELHI",FontFactory.GetFont("Arial",14,iTextSharp.text.Font.BOLD,BaseColor.BLACK)));
                cell.Colspan=7;
                cell.HorizontalAlignment=0;
                table.AddCell(cell);
               
                Paragraph para = new Paragraph("DCS Clinical Report-Technician wise", FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
                para.Alignment = Element.ALIGN_CENTER;
                iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
                png.ScaleToFit(105f, 105f);
                png.Alignment = Element.ALIGN_RIGHT;
                SqlConnection conn=new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
                SqlCommand cmd = new SqlCommand("Select t.technician_id,td.Technician_first_name,td.Technician_middle_name,td.Technician_last_name,t.technician_dob,t.technician_sex,td.technician_type from Techniciandetail td,Technician t where td.technician_id=t.technician_id and td.status=1", conn);
                conn.Open();
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                table.AddCell("ID");
                table.AddCell("First Name");
                table.AddCell("Middle Name");
                table.AddCell("Last Name");
                table.AddCell("DOB" );
                table.AddCell("Gender");
                table.AddCell("Designation");
                while (dr.Read())
                {
                    table.AddCell(dr[0].ToString());
                    table.AddCell(dr[1].ToString());
                    table.AddCell(dr[2].ToString());
                    table.AddCell(dr[3].ToString());
                    table.AddCell(dr[4].ToString());
                    table.AddCell(dr[5].ToString());
                    table.AddCell(dr[6].ToString());
                }
                dr.Close();
                    table.SpacingBefore = 15f;
                    
                    doc.Add(para);
                    doc.Add(png);
                   
                    doc.Add(table);
                doc.Close();
                System.Diagnostics.Process.Start("Technician22.pdf");
            }

however i have few problems that have been troubling me now.

1) how can i place or make my paragraph(DCS Clinical Report-Technician wise) appear in center with image(logo5.png) immmediately to it's right position?

 

2) how can i make my column headers(ID,First Name,Middle Name,Last Name,DOB,Gender and Designation) appear in bold?

 

As you can see in below code in c# on how i make my pdf report show or appear in screen upon creation.

 System.Diagnostics.Process.Start("Technician22.pdf");

where Technician22.pdf is name of my pdf report/file.

So my final question is

 

3) how can i include a dialog box appear in screen upon creation of pdf report from c# windows forms which enables user to save pdf report/file to any location where he chooses to save?

 

I have browsed through sourceforge.net/projects/itextsharp but no success.

I know i have to do some modifications in my code but i dont know how to do it.!

Can anyone help me please.! any help or guidance in solving this problem would be greatly appreciated.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download