Print an image of a folder with PrintDialog and PrinterSettings

0

Good, you see I have a small application that creates stickers, those stickers are saved in .jpg format and later my goal is to print the problem I have is that I do not know how to pass the file path to the printer

   Dim fileName As String = Path.Combine(folder, "Pegatina" & dia & mes & año & hora & min & seg & "_" & TextBox.Text & ".jpg")
   Dim vFoto As New Bitmap(Panel1.Width, Panel1.Height)
   Panel1.DrawToBitmap(vFoto, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
   vFoto.Save(fileName, Imaging.ImageFormat.Jpeg)
   archivo = "C:\Documents and Settings\Administrador\Escritorio\Pegatinas\Imagenes" & "\Pegatina" & dia & mes & año & hora & min & seg & "_" & TextBox.Text & ".jpg"

My question is how can I pass the variable file to a PrintDialog (). As much as I try and search I can not find a solution. Greetings.

    
asked by som1995 09.05.2017 в 17:55
source

1 answer

0

I'll attach the example:

Imports System.IO

Public Class ImprimirArchivo

Private Sub btnExaminar_Click(sender As Object, e As EventArgs) Handles btnExaminar.Click
    OpenFileDialog1.Title = "Seleccione una imagen."
    OpenFileDialog1.FileName = ""
    OpenFileDialog1.Multiselect = False
    OpenFileDialog1.Filter = "Imagenes|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff" +
                             "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|"
    OpenFileDialog1.ShowDialog()
    txtArchivo.Text = OpenFileDialog1.FileName
End Sub

Private Sub btnImprimir_Click(sender As Object, e As EventArgs) Handles btnImprimir.Click
    Dim rutaArchivo As String
    rutaArchivo = txtArchivo.Text.Trim()
    If (File.Exists(rutaArchivo)) Then
        'Si existe el archivo
        PrintDialog1.Document = PrintDocument1
        PrintDialog1.AllowPrintToFile = False
        PrintDialog1.AllowSelection = True
        PrintDialog1.AllowSomePages = True
        If (PrintDialog1.ShowDialog() = DialogResult.OK) Then
            PrintDocument1.Print()
        End If
    End If
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    'PrintDocument1.DocumentName = txtArchivo.Text.Trim()

    Dim g As Graphics
    g = e.Graphics
    Dim image As Image = image.FromFile(txtArchivo.Text.Trim())
    g.DrawImage(image, 0, 0)
    g.Dispose()

    e.HasMorePages = False
End Sub

End Class

The form was like this:

Here is the link to the example: Sample Project

    
answered by 09.05.2017 в 20:54