Increase distance between lines iTextSharp.
In the code below it brings me a long text. Is there a way to increase the spacing between lines?
Private Sub GeraTexto(ByVal pTexto as String, ByValPcaminho as String, ByVal pCPF as String)
Dim doc As New Document(iTextSharp.text.PageSize.A4.Rotate, 20, 20, 20, 20)
PdfWriter.GetInstance(doc, New FileStream(pCaminho + "/" & pCPF & ".pdf", FileMode.Create))
doc.Open()
doc.Add(New Paragraph(pTexto))
End Sub
the long texts that have very close spacing between the lines, we just need to increase the distance between the lines of these texts.
Private Sub CriaRelatorioPDF(ByVal pCPF As String, ByVal pDados As String, ByVal pEmenta As String, ByVal pDataEmissao As String, ByVal pImgAssPresidente As String,
ByVal pImgAssCoordenador As String, ByVal pAssPresidente As String, ByVal pAssCoordenador As String, ByVal pSenha As String)
Dim pCaminho As String
pCaminho = Server.MapPath("pdfs")
If File.Exists(pCaminho + "/" & pCPF & ".pdf") Then
File.Delete(pCaminho + "/" & pCPF & ".pdf")
End If
'Atribuir fontes do servidor na aplicação
FontFactory.RegisterDirectory("C:\WINDOWS\Fonts")
Dim cellFont As Font = FontFactory.GetFont("Soleto-Light", 16.0F, Font.NORMAL)
Dim cellFont3 As Font = FontFactory.GetFont("Soleto-Light", 9.0F, 0, Color.BLACK)
'Criar uma instância de document
Dim doc As New Document(iTextSharp.text.PageSize.A4.Rotate, 20, 20, 20, 20)
PdfWriter.GetInstance(doc, New FileStream(pCaminho + "/" & pCPF & ".pdf", FileMode.Create))
hfArquivo.Value = "pdfs/" & pCPF & ".pdf"
Dim phraseDados As Phrase = Nothing 'Texto
Dim phraseAss1 As Phrase = Nothing 'Frase da Assinatura 1
Dim cellAss1 As PdfPCell = Nothing 'Célula da assinatura 1
Dim cellImg1 As PdfPCell = Nothing 'Célula da imagem da assinatura 1
Dim phraseAss2 As Phrase = Nothing 'Frase da Assinatura 2
Dim cellAss2 As PdfPCell = Nothing 'Célula da assinatura 2
Dim cellImg2 As PdfPCell = Nothing 'Célula da imagem da assinatura 2
'Criar tabela ====================================================================
Dim table1 As PdfPTable = New PdfPTable(New Single() {10, 80, 10})
table1.DefaultCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED 'Justificar texto
table1.SpacingBefore = 220.0F 'Definir altura onde a tabela será criada
table1.DefaultCell.BorderWidth = 0 'Largura da borda da tabela 1
table1.DefaultCell.FixedHeight = 50.0F 'Altura da tabela 1
table1.AddCell(" ") 'Coluna 1, Linha 1
Dim htmlarraylist As ArrayList = HTMLWorker.ParseToList(New StringReader(pDados), Nothing)
phraseDados = New Phrase()
For k As Integer = 0 To htmlarraylist.Count - 1
phraseDados.Add(CType(htmlarraylist(k), IElement))
Next
' ALTERADO A LINHA COMENTADA ABAIXO PELAS 3 LINHAS NA SEQUÊNCIA
'table1.AddCell(phraseDados) 'Coluna 2, Linha 1
Dim parapTexto As Paragraph = New Paragraph(phraseDados)
parapTexto.SetLeading(1.0F, 2.5F)
table1.AddCell(parapTexto)
table1.AddCell(" ") 'Coluna 3, Linha 1
Dim table2 As PdfPTable = New PdfPTable(New Single() {10, 80, 10})
table2.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER 'Centralizar
table2.DefaultCell.BorderWidth = 0 'Largura da borda da tabela 2
table2.DefaultCell.FixedHeight = 50.0F 'Altura da tabela 2
table2.AddCell(" ") 'Coluna 1, Linha 1
table2.AddCell(pDataEmissao) 'Coluna 2, Linha 1
table2.AddCell(" ") 'Coluna 3, Linha 1
Dim table3 As PdfPTable = New PdfPTable(New Single() {10, 30, 10, 30, 10})
phraseAss1 = New Phrase()
phraseAss1.Add(New Chunk(pAssPresidente & vbLf & "Diretor Presidente", FontFactory.GetFont("Soleto-Light", 9, Font.NORMAL, Color.BLACK)))
phraseAss2 = New Phrase()
phraseAss2.Add(New Chunk(pAssCoordenador & vbLf & "Coordenador(a)", FontFactory.GetFont("Soleto-Light", 9, Font.NORMAL, Color.BLACK)))
table3.SpacingBefore = 60.0F 'Definir altura onde a tabela será criada
table3.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER 'Centralizar texto
table3.DefaultCell.BorderWidth = 0 'Largura da borda da tabela
table3.AddCell("") 'Coluna 1, Linha 1
table3.AddCell("") 'Coluna 2, Linha 1
table3.AddCell(" ") 'Coluna 3, Linha 1
table3.AddCell(" ") 'Coluna 4, Linha 1
table3.AddCell(" ") 'Coluna 5, Linha 1
table3.AddCell("") 'Coluna 1, Linha 1
table3.AddCell("_______________________________") 'Coluna 2, Linha 1
table3.AddCell(" ") 'Coluna 3, Linha 1
table3.AddCell("_______________________________") 'Coluna 4, Linha 1
table3.AddCell(" ") 'Coluna 5, Linha 1
table3.AddCell(" ") 'Coluna 1, Linha 2
table3.AddCell(phraseAss1) 'Coluna 2, Linha 2
table3.AddCell(" ") 'Coluna 3, Linha 2
table3.AddCell(phraseAss2) 'Coluna 4, Linha 2
table3.AddCell(" ") 'Coluna 5, Linha 2
table3.AddCell(" ") 'Coluna 1, Linha 2
table3.AddCell("") 'Coluna 2, Linha 2
table3.AddCell(" ") 'Coluna 3, Linha 2
table3.AddCell("") 'Coluna 4, Linha 2
table3.AddCell(" ") 'Coluna 5, Linha 2
'Definindo a imagem de fundo do documento
Dim imageFilePath As String = Server.MapPath("~/imagens/Cedula_Certificado_01.jpg")
Dim jpg As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageFilePath)
jpg.ScaleToFit(850, 650)
jpg.Alignment = iTextSharp.text.Image.UNDERLYING
jpg.SetAbsolutePosition(0, 0)
'Definindo imagem da assinatura 1
Dim imageFilePath2 As String = pImgAssPresidente
Dim jpgAssina1 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageFilePath2)
jpgAssina1.ScalePercent(10.0F)
jpgAssina1.Alignment = iTextSharp.text.Image.UNDERLYING
jpgAssina1.SetAbsolutePosition(155, 100)
'Definindo imagem da assinatura 2
Dim imageFilePath3 As String = pImgAssCoordenador
Dim jpgAssina2 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageFilePath3)
jpgAssina2.ScalePercent(10.0F)
jpgAssina2.Alignment = iTextSharp.text.Image.UNDERLYING
jpgAssina2.SetAbsolutePosition(440, 100)
'=================================================================================
doc.Open()
doc.Add(jpg)
doc.Add(jpgAssina1) 'Assinatura do Presidente
doc.Add(jpgAssina2) 'Assinatura do Coordenador
doc.Add(New Paragraph(" "))
doc.Add(table1)
doc.Add(New Paragraph(" "))
doc.Add(table2)
doc.Add(table3)
doc.NewPage()
doc.Add(New Paragraph(" "))
doc.Add(New Paragraph(" "))
Dim tbEmenta As PdfPTable = New PdfPTable(New Single() {100})
tbEmenta.DefaultCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED 'Justificar
tbEmenta.DefaultCell.BorderWidth = 0
Dim phraseEmenta = New Phrase()
Dim html As ArrayList = HTMLWorker.ParseToList(New StringReader(pEmenta), Nothing)
For k As Integer = 0 To html.Count - 1
phraseEmenta.Add(CType(html(k), IElement))
Next
Dim parapTexto1 As Paragraph = New Paragraph(phraseEmenta)
parapTexto1.SetLeading(1.0F, 2.5F)
tbEmenta.AddCell(parapTexto1)
'tbEmenta.AddCell(phraseEmenta)
doc.Add(tbEmenta)
doc.NewPage()
doc.Close()
' =================================================================================
' #####################################################################################
' CRIAR SENHA NO DOCUMENTO
' #####################################################################################
Dim bytes As Byte() = File.ReadAllBytes(pCaminho + "/" & pCPF & ".pdf")
Using input As New MemoryStream(bytes)
Using output As New MemoryStream()
Dim password As String = pCPF
Dim reader As New PdfReader(input)
PdfEncryptor.Encrypt(reader, output, True, password, password, PdfWriter.ALLOW_SCREENREADERS)
bytes = output.ToArray()
End Using
End Using
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.pdf")
Response.ContentType = "application/pdf"
Response.Buffer = True
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.BinaryWrite(bytes)
Response.End()
Response.Close()
' #####################################################################################
If File.Exists(pCaminho + "/" & pCPF & ".pdf") Then
hlDownload.NavigateUrl = "~/aluno/pdfs/" & pCPF & ".pdf"
hlDownload.Visible = True
End If
End Sub
Grateful,
ilano