hi i will send code below and Send Output in File Please Check
I find Two Bug Which is marked in Attachment
Code:
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports PdfSharp.Pdf
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Fonts
Imports PdfSharp.Forms
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim PrnDoc As New System.Drawing.Printing.PrintDocument
Dim PrnPreview As New PrintPreviewDialog
AddHandler PrnDoc.PrintPage, AddressOf PrnDoc_PrintPage
'PrnPreview.wi
PrnPreview.Document = PrnDoc
PrnPreview.PrintPreviewControl.Zoom = 1.5
PrnPreview.ShowDialog()
End Sub
Private Sub PrnDoc_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)
Dim rec As RectangleF
Dim Printx As Single
Dim PrintY As Single
Dim gfx As Graphics
Dim Ind_Col As Long
Dim Ind_Row As Long
Dim Width1 As Single
Dim Height1 As Single
Dim TopMargine As Single
Dim LeftMargine As Single
Dim TmpStr1 As String
gfx = e.Graphics
gfx.SmoothingMode = SmoothingMode.HighQuality
gfx.PageUnit = GraphicsUnit.Point
gfx.TextRenderingHint = TextRenderingHint.AntiAlias
'gfx.TextContrast = 0
gfx.CompositingQuality = CompositingQuality.HighQuality
gfx.InterpolationMode = InterpolationMode.HighQualityBilinear
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality
Width1 = 144
Height1 = 14.17323
LeftMargine = 18
TopMargine = 18
PrintY = TopMargine
For Ind_Row = 1 To 3
Printx = LeftMargine
For Ind_Col = 1 To 3
rec = New RectangleF(Printx, PrintY, Width1, Height1)
If Ind_Col <> 2 Then
'--- Left Line
Dim pen As New Pen(Color.Black)
pen.Alignment = PenAlignment.Left
pen.Width = 1
gfx.DrawLine(pen, Printx + (pen.Width / 2), PrintY, Printx + (pen.Width / 2), PrintY + Height1)
rec.X = rec.X + pen.Width
pen.Dispose()
'--- Right Line
pen = New Pen(Color.Black)
pen.Alignment = PenAlignment.Center
pen.Width = 1
gfx.DrawLine(pen, Printx + Width1 - (pen.Width / 2), PrintY, Printx + Width1 - (pen.Width / 2), PrintY + Height1)
rec.Width = rec.Width - pen.Width
pen.Dispose()
If Ind_Row = 1 Then
'--- Top Line
pen = New Pen(Color.Black)
pen.Alignment = PenAlignment.Center
pen.Width = 1
gfx.DrawLine(pen, Printx, PrintY + (pen.Width / 2), Printx + Width1, PrintY + (pen.Width / 2))
rec.Y = rec.Y + pen.Width
pen.Dispose()
End If
'--- Bottom Line
pen = New Pen(Color.Black)
pen.Alignment = PenAlignment.Center
pen.Width = 1
gfx.DrawLine(pen, Printx, PrintY + Height1 - (pen.Width / 2), Printx + Width1, PrintY + Height1 - (pen.Width / 2))
rec.Height = rec.Height - pen.Width
pen.Dispose()
'--- For Gap From Line
rec.X = rec.X + 1
rec.Y = rec.Y + 1
rec.Height = rec.Height - 1
rec.Width = rec.Width - 1
End If
Dim Format As New StringFormat
Format.FormatFlags = StringFormatFlags.NoWrap
Format.Trimming = StringTrimming.None
If Ind_Col = 1 Then
Format.Alignment = StringAlignment.Far
Format.LineAlignment = StringAlignment.Center
ElseIf Ind_Col = 2 Then
Format.Alignment = StringAlignment.Center
Format.LineAlignment = StringAlignment.Center
Else
Format.Alignment = StringAlignment.Far
Format.LineAlignment = StringAlignment.Center
End If
TmpStr1 = "Row " + Ind_Row.ToString() + "Cell " + Ind_Col.ToString()
If Ind_Col = 1 Then
TmpStr1 = "3W4W5W6W7W8W9W1W2W3W4W5W6W7W8W9"
End If
gfx.DrawString(TmpStr1, New Font("Arial", 8, FontStyle.Regular), System.Drawing.Brushes.Black, rec, Format)
Printx = Printx + Width1
Next
PrintY = PrintY + Height1
Next
e.HasMorePages = False
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim PdfDoc As PdfDocument
Dim PdfPage As PdfPage
Dim PgInfo As PaperSize
PdfDoc = New PdfDocument()
PdfDoc.Info.Author = My.Application.Info.CompanyName
PdfDoc.Info.Creator = "Ankit Patel"
PdfDoc.Info.Subject = "Export From Report Lib"
PdfDoc.Info.Title = My.Application.Info.Title
PdfPage = PdfDoc.AddPage()
'PdfPage.Size = PageSize.Undefined
PdfPage.Width = 841.68
PdfPage.Height = 595.44
PdfPage.Orientation = PageOrientation.Portrait
Dim rec As RectangleF
Dim Printx As Single
Dim PrintY As Single
Dim gfx As XGraphics
Dim Ind_Col As Long
Dim Ind_Row As Long
Dim Width1 As Single
Dim Height1 As Single
Dim TopMargine As Single
Dim LeftMargine As Single
Dim TmpStr1 As String
gfx = XGraphics.FromPdfPage(PdfPage, XGraphicsPdfPageOptions.Append, XGraphicsUnit.Point)
gfx.SmoothingMode = SmoothingMode.HighQuality
Width1 = 144
Height1 = 14.17323
LeftMargine = 18
TopMargine = 18
PrintY = TopMargine
For Ind_Row = 1 To 3
Printx = LeftMargine
For Ind_Col = 1 To 3
rec = New RectangleF(Printx, PrintY, Width1, Height1)
If Ind_Col <> 2 Then
'--- Left Line
Dim pen As New XPen(Color.Black)
'pen.Alignment = PenAlignment.Left
pen.Width = 1
gfx.DrawLine(pen, Printx + (pen.Width / 2), PrintY, Printx + (pen.Width / 2), PrintY + Height1)
rec.X = rec.X + pen.Width
pen = Nothing
'--- Right Line
pen = New XPen(Color.Black)
'pen.Alignment = PenAlignment.Center
pen.Width = 1
gfx.DrawLine(pen, Printx + Width1 - (pen.Width / 2), PrintY, Printx + Width1 - (pen.Width / 2), PrintY + Height1)
rec.Width = rec.Width - pen.Width
pen = Nothing
If Ind_Row = 1 Then
'--- Top Line
pen = New XPen(Color.Black)
'pen.Alignment = PenAlignment.Center
pen.Width = 1
gfx.DrawLine(pen, Printx, PrintY + (pen.Width / 2), Printx + Width1, PrintY + (pen.Width / 2))
rec.Y = rec.Y + pen.Width
pen = Nothing
End If
'--- Bottom Line
pen = New XPen(Color.Black)
'pen.Alignment = PenAlignment.Center
pen.Width = 1
gfx.DrawLine(pen, Printx, PrintY + Height1 - (pen.Width / 2), Printx + Width1, PrintY + Height1 - (pen.Width / 2))
rec.Height = rec.Height - pen.Width
pen = Nothing
'--- For Gap From Line
rec.X = rec.X + 1
rec.Y = rec.Y + 1
rec.Height = rec.Height - 1
rec.Width = rec.Width - 1
End If
Dim Format As New XStringFormat
'Format.FormatFlags = XStringFormat.NoWrap
'Format.Trimming = XStringFormat.None
If Ind_Col = 1 Then
Format.Alignment = XStringAlignment.Far
Format.LineAlignment = XStringAlignment.Center
ElseIf Ind_Col = 2 Then
Format.Alignment = XStringAlignment.Center
Format.LineAlignment = XStringAlignment.Center
Else
Format.Alignment = XStringAlignment.Far
Format.LineAlignment = XStringAlignment.Center
End If
TmpStr1 = "Row " + Ind_Row.ToString() + "Cell " + Ind_Col.ToString()
If Ind_Col = 1 Then
TmpStr1 = "3W4W5W6W7W8W9W1W2W3W4W5W6W7W8W9"
End If
gfx.DrawString(TmpStr1, New XFont("Arial", 8, FontStyle.Regular), XBrushes.Black, rec, Format)
Printx = Printx + Width1
Next
PrintY = PrintY + Height1
Next
PdfDoc.Save("E:\AdpError.pdf")
End Sub
End Class