Hallo,
Ich brauche Hilfe zu einem Drucker Problem.
Ich möchte von meinem Programm aus eine PDF Datei speichern. Ich verwende dafür den Treiber „Microsoft Print to PDF“
Wenn ich den Button drücke öffnet sich ein Dialog Fenster wo ich eine Datei Name eingeben muss.
Ich möchte aber dass der Name vom Code aus eingegeben wird.
Siehe bitte den Code
Was mache ich hier falsch?
Danke im Voraus
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles _
Button1.Click
dlgPrint.PrinterSettings.PrinterName = cboInstalledPrinters.Text
dlgPrint.PrinterSettings.PrintFileName = txtOneDrive.Text & "\" & _
lblRecipeHead.Text & ".pdf"
dlgPrint.PrintToFile = True
dlgPrint.AllowPrintToFile = True
PrintDocument.Print()
End Sub
Private Sub PrintDocument_PrintPage(ByVal sender As Object, ByVal e As _
System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument.PrintPage
' ' To print the boundaries of the current page margins
' uncomment the next line:
Dim RectBorder As Rectangle = New Rectangle(e.MarginBounds.X - _
7, e.MarginBounds.Top - 7, e.MarginBounds.Width + 7, _
e.MarginBounds.Height + 7)
e.Graphics.DrawRectangle(System.Drawing.Pens.Blue, RectBorder)
' make the RichTextBoxEx calculate and render as much text as
' will
' fit on the page and remember the last character printed for
' the
' beginning of the next page
m_nFirstCharOnPage = RTBEx.FormatRange(False, _
e, _
m_nFirstCharOnPage, _
RTBEx.TextLength)
' Indsæt billede fra picRecipe1
Dim pb As New PictureBox With {.SizeMode = _
PictureBoxSizeMode.Zoom}
If Not Clipboard.GetImage Is Nothing Then
pb.Image = Clipboard.GetImage
pb.Size = Clipboard.GetImage.Size
Dim Ratio As Single = pb.Width / pb.Height
If pb.Width > 320 Then
pb.Size = New Size(320, 320 / Ratio)
ElseIf pb.Height > 240 Then
pb.Size = New Size(240 / Ratio, 240)
End If
Dim Rect As New Rectangle(e.MarginBounds.Width + _
e.MarginBounds.Left - pb.Width - 7, e.MarginBounds.Top + _
7, pb.Width, pb.Height)
e.Graphics.DrawImage(pb.Image, Rect)
End If
If File.Exists(Application.StartupPath & "\Icons\Logo.png") Then
Dim logo As Image = Image.FromFile(Application.StartupPath _
& "\Icons\Logo.png")
Dim RectLogo As Rectangle = New Rectangle(e.MarginBounds.X _
- 32, e.MarginBounds.Top + e.MarginBounds.Height, 64, 64)
e.Graphics.DrawImage(logo, RectLogo)
End If
e.Graphics.DrawString(Application.ProductName & " - © 2015" & _
"Nuhme. Alle rettigheder forbeholdes", New Font("Calibri", _
12, FontStyle.Bold), Brushes.RoyalBlue, e.MarginBounds.X + _
15, e.MarginBounds.Top + e.MarginBounds.Height + 25)
Dim Oprettet As String = "Oprettet / rettet d. : " & _
RecipeEditDate
Dim widthText As Single = e.Graphics.MeasureString(Oprettet, _
New Font("Calibri", 9, FontStyle.Regular)).Width
e.Graphics.DrawString(Oprettet, New Font("Calibri", 9, _
FontStyle.Regular), Brushes.Black, e.MarginBounds.X + _
e.MarginBounds.Width - widthText, e.MarginBounds.Top + _
e.MarginBounds.Height + 60)
' check if there are more pages to print
If (m_nFirstCharOnPage < RTBEx.TextLength) Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub 0 |