Path image Console Application VB.net

-2

Hello, I'd like a help please regarding a problem I'm having to insert an image into my console application project. I can only use the absolute path when I send the project the client will have to change how do I do that does not have to happen?

Private Function cabecalhoPolicardPDF() As PdfPTable
    Try
        Dim img = iTextSharp.text.Image.GetInstance("G:\projetolimpo\up_sgp-master\RotinaRelacaoLimiteComplementar\img\logo-sombra.jpg")
    Dim table = New PdfPTable(2)
        table.HorizontalAlignment = Element.ALIGN_LEFT
        table.TotalWidth = 500
        Dim widths() As Integer = {190, 310}
        table.SetWidths(widths)

        Dim cell As New PdfPCell(img)
        cell.Border = 0
        cell.HorizontalAlignment = Element.ALIGN_RIGHT
        cell.VerticalAlignment = Element.ALIGN_MIDDLE


        Dim cell2 As New PdfPCell()

        Dim VerdanaCab As iTextSharp.text.Font = FontFactory.GetFont("Verdana", 13, iTextSharp.text.Font.BOLD)
        VerdanaCab.SetColor(245, 145, 0)
        Dim Verdana As iTextSharp.text.Font = FontFactory.GetFont("Verdana", 9, iTextSharp.text.Font.BOLD)
        Dim VerdanaN As iTextSharp.text.Font = FontFactory.GetFont("Verdana", 9, iTextSharp.text.Font.NORMAL)

        Dim p0 As New Phrase()
        Dim c1 As New Chunk("SISTEMA UP BRASIL" & Environment.NewLine & Environment.NewLine, VerdanaCab)
        p0.Add(c1)
        p0.Leading = 50

        cell2.AddElement(p0)
        cell2.SetLeading(0.0F, 0.0F)


        c1 = New Chunk("Razão Social: ", Verdana)
        Dim c2 As New Chunk("Policard Systems e Serviços S/A" & Environment.NewLine, VerdanaN)
        Dim p1 As New Phrase()

        p1.Leading = 10
        p1.Add(c1)
        p1.Add(c2)


        cell2.AddElement(p1)

        cell2.Border = 0
        cell2.HorizontalAlignment = Element.ALIGN_LEFT
        table.AddCell(cell2)
        table.AddCell(cell)
        table.HorizontalAlignment = Element.ALIGN_LEFT

        Return table
    Catch ex As Exception
        Throw ex
    End Try
End Function

    
asked by anonymous 25.09.2018 / 04:50

2 answers

1

Considering that the root of your executable is in G:\projetolimpo\up_sgp-master\ you can use the GetCurrentDirectory() method and complement with the rest of the path.

Dim path = Directory.GetCurrentDirectory() + "\RotinaRelecaoLimiteComplementar\img\logo-sombra.jpg"

Dim img = iTextSharp.text.Image.GetInstance(path)
    
05.10.2018 / 18:45
0

You need to create a way for your client to edit this value through your application, which should persistently store this information in a text file or database, or you can have a global variable that receives this value ( in this second option the value will be stored in temporary memory RAM)

It would look more or less like this.

Dim pathImage string

Dim img=iTextSharp.text.Image.GetInstance(pathImage)
    
25.09.2018 / 12:19