Image Path Console Application VB.net

Asked

Viewed 90 times

-2

Hello would 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 sending the project the client will have to change how I do not need 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

inserir a descrição da imagem aqui

  • Include your actual code and not a screen print... Will the file be in the same structure as the executable? will use some environment variable? save to.Settings app or some config file?

  • Hello Leandro, sure I’ll put the code, well yes it will be in the same structure, it will work so I will have a console application that used these methods to create a PDF and need in the pdf have this logo.

2 answers

1


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

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

Dim img = iTextSharp.text.Image.GetInstance(path)

0

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

It would look something like this.

Dim pathImage string

Dim img=iTextSharp.text.Image.GetInstance(pathImage)
  • Hello Rodolfo thanks for your attention, man so there is no way I do the same Asp net only take the path of the folder?

  • Opa you can use the Filedialog to open that interaction window for the client to search the image in a folder on your computer, then you store the path returned by Filedialog, so that next time it uses this path in the display of your image, I don’t know if it’s clear to you that answer.

  • Hello Rodolfo, thanks again for the good attention and that so this application is a routine that runs at dawn and mounts a PDF I never developed console Aplication so so the weirdness, so this option I think would not work I think I will choose to use a constant really thank you.

  • Hello Rodrigo, being a console application really this option will not work, the ideal is to store in a variable even, but creates a method, so that you or your client can change later.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.