Torna al Thread

' Creare un nuovo documento PDF Dim pdfdoc As New PdfSharp.Pdf.PdfDocument() pdfdoc.Info.Title = "prova" pdfdoc.Info.Author = "" ' Crea una pagina vuota Dim pdfpage As PdfSharp.Pdf.PdfPage = pdfdoc.AddPage() pdfpage.Size = PdfSharp.PageSize.Letter ' Modifica la dimensione della pagina pdfpage.Orientation = PageOrientation.Portrait ' Modificare la proprietà di orientamento ' Ottieni un oggetto XGraphics per il disegno Dim xGrap As XGraphics = XGraphics.FromPdfPage(pdfpage) xGrap.MUH = PdfFontEncoding.Unicode xGrap.MFEH = PdfFontEmbedding.None 'Utilizzato per mantenere l'area del testo personalizzato Dim textformater As New XTextFormatter(xGrap) ' Crea caratteri Dim titlefontB As XFont = New XFont("Times New Roman", 14, XFontStyle.Bold) Dim tableheaderB As XFont = New XFont("Times New Roman", 16, XFontStyle.Bold) Dim bodyfontB As XFont = New XFont("Times New Roman", 10, XFontStyle.Bold) Dim bodyfont As XFont = New XFont("Times New Roman", 10, XFontStyle.Regular) ' Disegnare il testo Dim x As Double = 100 '250 Dim y As Double = 20 Dim width As Double = 600 Dim height As Double = 30 ' Dichiarazione della tabella (altezza e larghezza della dichiarazione delle colonne) y = y + 30 ' Aumentare l'altezza dall'alto Dim Incarico As New XRect(20, y, 150, 20) Dim liello As New XRect(150, y, 150, 20) Dim Decorrenza As New XRect(290, y, 100, 20) Dim Termine As New XRect(380, y, 100, 20) Dim Indennita As New XRect(470, y, 80, 20) Dim Importo As New XRect(540, y, 60, 20) ' Disegnare la tabella Row Borders xGrap.DrawRectangle(XPens.Black, XBrushes.White, Incarico) 'Utilizza diverso colore per la colonna xGrap.DrawRectangle(XPens.Black, XBrushes.White, Livello) xGrap.DrawRectangle(XPens.Black, XBrushes.White, Decorrenza) xGrap.DrawRectangle(XPens.Black, XBrushes.White, Termine) xGrap.DrawRectangle(XPens.Black, XBrushes.White, Indennità) xGrap.DrawRectangle(XPens.Black, XBrushes.White, Importo) ' Scrittura del testo dell'intestazione della tabella xGrap.DrawString("INCARICO", bodyfontB, XBrushes.Black, Incarico, XStringFormats.TopCenter) xGrap.DrawString("LIVELLO", bodyfontB, XBrushes.Black, Livello, XStringFormats.TopCenter) xGrap.DrawString("DECORRENZA", bodyfontB, XBrushes.Black, Decorrenza, XStringFormats.TopCenter) xGrap.DrawString("TERMINE", bodyfontB, XBrushes.Black, Termine, XStringFormats.TopCenter) xGrap.DrawString("INDENNITA", bodyfontB, XBrushes.Black, Indennita, XStringFormats.TopCenter) xGrap.DrawString("IMPORTO", bodyfontB, XBrushes.Black, Importo, XStringFormats.TopCenter) For i = 0 To ds_Comando.Tables(0).Rows.Count - 1 ' Scrittura del contenuto del corpo della tavola y = y + 20 'aumentare l'altezza della posizione del contenuto dall'alto Dim IncaricoVal As New XRect(20, y, 150, height) Dim LivelloVal As New XRect(150, y, 150, height) Dim DecorrenzaVal As New XRect(290, y, 100, height) Dim TermineVal As New XRect(380, y, 100, height) Dim IndennitaVal As New XRect(470, y, 80, height) Dim ImportoVal As New XRect(540, y, 60, height) ' Disegnare la tabella Row Borders xGrap.DrawRectangle(XPens.Black, XBrushes.White, IncaricoVal) 'Utilizza diverso colore per la colonna xGrap.DrawRectangle(XPens.Black, XBrushes.White, LivelloVal) xGrap.DrawRectangle(XPens.Black, XBrushes.White, DecorrenzaVal) xGrap.DrawRectangle(XPens.Black, XBrushes.White, TermineVal) xGrap.DrawRectangle(XPens.Black, XBrushes.White, IndennitaVal) xGrap.DrawRectangle(XPens.Black, XBrushes.White, ImportoVal) textformater.DrawString(ds_Comando.Tables(0).Rows(i).Item(6), bodyfont, XBrushes.Black, IncaricoVal, XStringFormats.TopLeft) textformater.DrawString(ds_Comando.Tables(0).Rows(i).Item(3), bodyfont, XBrushes.Black, LivelloVal, XStringFormats.TopLeft) xGrap.DrawString(ds_Comando.Tables(0).Rows(i).Item(4), bodyfont, XBrushes.Black, DecorrenzaVal, XStringFormats.TopCenter) xGrap.DrawString(ds_Comando.Tables(0).Rows(i).Item(5), bodyfont, XBrushes.Black, TermineVal, XStringFormats.TopCenter) xGrap.DrawString(ds_Comando.Tables(0).Rows(i).Item(7), bodyfont, XBrushes.Black, IndennitaVal, XStringFormats.TopCenter) xGrap.DrawString(Format(CType(ds_Comando.Tables(0).Rows(i).Item(8), Decimal), "###,##0.00"), bodyfont, XBrushes.Black, ImportoVal, XStringFormats.TopCenter) Next ' Salvare il documento Dim pdfDate As String = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString() Dim filename As String = Convert.ToString(AppDomain.CurrentDomain.BaseDirectory) + "Report_PDF\Indennita.pdf" 'Choose the path where the file want to save pdfdoc.Save(filename) pdfdoc.Close() pdfdoc.Dispose() Process.Start(filename)
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5