Hallo Stefan, es funktioniert jetzt alles vielen vielen Dank, lediglich das PDF Template wird nicht benutzt?
Hast Du da evtl. eine Idee woran es liegen kann? -> Dim oldFile As String = "templates/template.pdf" Der Code sieht nun wie folgt aus:
Imports iTextSharp.text.pdf
Imports iTextSharp.text
Imports System.IO
Public Class Form1
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Label2.Click
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnclose.Click
Me.Close()
End Sub
Private Sub btngen_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btngen.Click
checklengh(txtcode.Text)
'-------------------------------------------
Dim BarcodePath = System.IO.Path.Combine(Application.StartupPath, _
"barcode/barcode.bmp")
EaN13Barcode.Value = txtcode.Text
SaveAsBitmap(EaN13Barcode, BarcodePath)
'-------------------------------------------
Dim oldFile As String = "templates/template.pdf"
Dim newFile As String = "output/etikett.pdf"
Dim reader As New PdfReader(oldFile)
Dim size As Rectangle = reader.GetPageSizeWithRotation(1)
Dim document As New Document(size)
Dim fs As New FileStream(newFile, FileMode.Create, FileAccess.Write)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, fs)
document.Open()
Dim cb As PdfContentByte = writer.DirectContent
Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, _
BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
cb.SetColorFill(BaseColor.BLACK)
cb.SetFontAndSize(bf, 16)
cb.BeginText()
Dim platz As String = txtplatz.Text
Dim name As String = txtname.Text
Dim nr As String = txtnr.Text
Dim code As String = txtcode.Text
cb.ShowTextAligned(0, platz, 220, 204, 0)
cb.ShowTextAligned(0, name, 220, 145, 0)
cb.ShowTextAligned(0, nr, 220, 125, 0)
cb.ShowTextAligned(1, code, 283, 14, 0)
cb.EndText()
Dim page As PdfImportedPage = writer.GetImportedPage(reader, 1)
'-------------------------------------------
Dim BarcodeImage As iTextSharp.text.Image = Image.GetInstance( _
BarcodePath)
BarcodeImage.SetAbsolutePosition(190, 0)
document.Add(BarcodeImage)
'-------------------------------------------
document.Close()
fs.Close()
writer.Close()
reader.Close()
MsgBox("Label erfolgreich gespeichert.", MsgBoxStyle.Information,
Title:="Information")
End Sub
Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnprint.Click
Dim path = System.IO.Path.Combine(Application.StartupPath, _
"output/etikett.pdf")
Process.Start(path)
End Sub
Private Sub SaveAsBitmap(ByVal control As Control, ByVal fileName As String)
'getthe instance of the graphics from the control
Dim g As Graphics = control.CreateGraphics()
'new bitmap object to save the image
Dim bmp As New Bitmap(control.Width, control.Height)
'Drawing control to the bitmap
control.DrawToBitmap(bmp, New System.Drawing.Rectangle(0, 0, _
control.Width, control.Height))
bmp.Save(fileName)
bmp.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
End Sub
Private Sub txtcode_TextChanged(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles txtcode.TextChanged
txtcode.MaxLength = 12
Dim MeineZahl As Double = 0
If Not Double.TryParse(txtcode.Text, MeineZahl) Then
MsgBox("Bitte nur Zahlen eintragen, 12 Zeichen sind erforderlich!", _
MsgBoxStyle.Critical,
Title:="Bitte gültige Werte eingeben")
End If
End Sub
Private Sub checklengh(ByVal txtcode As String)
If Not txtcode.Length > 12 Then
MsgBox("Der EAN Code muss 12 Zeichen haben", MsgBoxStyle.Critical,
Title:="Bitte gültige Werte eingeben")
txtcode = vbNullString
Else
End If
End Sub
End Class |