Naidu AMMAN

Naidu AMMAN

  • NA
  • 37
  • 34.9k

In my code how to edit font size for pdf doc in buttn2-click

Oct 31 2014 6:17 AM
Please send as soon as possible.
 
 
Imports System.IO
Imports System.Data
Imports System.Reflection
Imports iTextSharp.text
Imports iTextSharp.text.pdf
''Imports Spire.Pdf
''Imports Spire.Pdf.Graphics
''Imports Spire.Pdf.Tables
Public Class frmDailyReport
Dim grpid As Integer = 0
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
grid_data.Tables.Clear()
Dim strsql As String
Dim m_db As New CDataAccess
''strsql = "SELECT tblcollection.VehicleNumber, tblcollection.VehicleType, Format(INDATE,'dd/mm/yyyy') AS VehicleINDATE, Format(INDATE,'hh:nn:ss') AS VehicleINTIME,DeviceID, Amount, SupervisorID, Fromtime, Totime, ExtraAmountperHour, Billtype, SupervisorName, ShiftNo FROM tblcollection where INDATE>=#" & DtFrom.Value.Date.ToString("MM/dd/yyyy") & "# "
strsql = "SELECT tblcollection.VehicleNumber as V_Number, tblcollection.VehicleType as V_Type, Format(INDATE,'dd/mm/yy') AS INDate, Format(INDATE,'hh:nn:ss') AS INTime,DeviceID, Amount, SupervisorID, Fromtime, Totime, ExtraAmountperHour as ExtraAmount, Billtype, SupervisorName FROM tblcollection where INDATE>=#" & DtFrom.Value.Date.ToString("MM/dd/yyyy") & "# "
grid_data = m_db.getdata(strsql, strconnection)
If Not grid_data Is Nothing Then
DataGridView1.DataSource = grid_data.Tables(0)
Else
MsgBox("No Records found", MsgBoxStyle.Information)
End If
End Sub
Private grid_data As New DataSet
Private Sub loaddata()
Dim strsql As String = ""
Dim m_ds As DataSet
Dim m_db As New CDataAccess
strsql = "SELECT tblcollection.VehicleNumber, tblcollection.VehicleType, Format(INDATE,'dd/mm/yy') AS InDate, Format(INDATE,'hh:nn:ss') AS INTime,DeviceID, Amount, SupervisorID, Fromtime, Totime, ExtraAmountperHour, Billtype, SupervisorName, ShiftNo FROM tblcollection"
''strsql = "SELECT DISTINCT tblcollection.VehicleType, Count(tblcollection.InSlip) AS CountofInSlip, Count(tblcollection.OutSlip) AS CountOfOutSlip, Count(tblcollection.OutSlip) AS CountOfOutSlip1, Count(InSlip)-Count(OutSlip) AS balance FROM tblcollection GROUP BY tblcollection.VehicleType;"
m_ds = m_db.getdata(strsql, strconnection)
If Not m_ds Is Nothing Then
DataGridView1.DataSource = m_ds.Tables(0).DefaultView
DataGridView1.AutoResizeColumns()
DataGridView1.ReadOnly = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (grid_data.Tables.Count = 0) Then
MsgBox("Click on GenerateReport Before use this Expordata Otherwise No Records will be Found", MsgBoxStyle.Critical)
Return
End If
txtbrowse.Text = ""
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
txtbrowse.Text = SaveFileDialog1.FileName() + ".pdf"
Dim pdfTable As New PdfPTable(DataGridView1.ColumnCount)
pdfTable.DefaultCell.Padding = 0 '3
pdfTable.WidthPercentage = 101 '30
pdfTable.HorizontalAlignment = Element.ALIGN_RIGHT
pdfTable.DefaultCell.BorderWidth = 1
pdfTable.HorizontalAlignment = 0
For Each column As DataGridViewColumn In DataGridView1.Columns
Dim cell As New PdfPCell(New Phrase(column.HeaderText))
cell.BackgroundColor = New iTextSharp.text.BaseColor(240, 240, 240)
pdfTable.AddCell(cell)
Next
'Adding DataRow
For Each row As DataGridViewRow In DataGridView1.Rows
For Each cell As DataGridViewCell In row.Cells
pdfTable.AddCell(cell.Value.ToString())
Next
Next
'Exporting to PDF
Using stream As New FileStream(txtbrowse.Text, FileMode.Create)
''Dim font1 As New PdfTrueTypeFont(New Font("Arial", 16.0F, FontStyle.Bold))
Dim pdfDoc As New Document(PageSize.A4, 20.0F, 20.0F, 20.0F, 20.0F)
'' Dim pdfDoc As New Document(PageSize.A4, 16.0F, FontStyle.Bold)
PdfWriter.GetInstance(pdfDoc, stream)
pdfDoc.Open()
pdfDoc.Add(pdfTable)
pdfDoc.Close()
stream.Close()
End Using
End If
End Sub
 
 
 when iam running the pdf saving like this

V_number

V-type

Indate

Intime

deviceId

Amount

supervisorId

Fromtime

Totime

Extraamount

billtype

supervisorname

111

2W

30/10/14

16:40:35

123456789123456

10.00

12345678

00H

02H

5

Postpaid-bill

TESTINGUSER

111

4W

30/10/14

16:40:45

123456789123456

10.00

12345678

00H

02H

10

Postpaid-bill

TESTINGUSER

 
But i want to save like this with correct font size.

V_number

V-type

Indate

Intime

deviceId

Amount

supervisorId

Fromtime

Totime

Extraamount

billtype

supervisorname

111

2W

30/10/14

16:40:35

123456789123456

10.00

12345678

00H

02H

5

Postpaid-bill

TESTINGUSER

111

4W

30/10/14

16:40:45

123456789123456

10.00

12345678

00H

02H

10

Postpaid-bill

TESTINGUSER