Hallo HenryV, danke für deinen Beitrag, funktioniert super!
Ich frage mich nur wieso er die Vorlage, also das PDF-Template nicht mehr nimmt?
Jemand eine Idee? Hier der aktuelle Code:
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
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
cb.ShowTextAligned(0, platz, 220, 204, 0)
cb.ShowTextAligned(0, name, 220, 145, 0)
cb.ShowTextAligned(0, nr, 220, 125, 0)
Dim bc As New iTextSharp.text.pdf.BarcodeEAN
bc.CodeType = iTextSharp.text.pdf.BarcodeEAN.EAN13
bc.TextAlignment = Element.ALIGN_CENTER
bc.Code = txtcode.Text
'bc.StartStopText = True
'bc.Extended = True
'bc.GenerateChecksum = True
'bc.ChecksumText = True
'bc.Font = Nothing
Dim imageEAN As iTextSharp.text.Image = bc.CreateImageWithBarcode(cb, _
iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK)
imageEAN.ScaleToFit(250, 60)
imageEAN.SetAbsolutePosition(190, 35)
cb.AddImage(imageEAN)
cb.EndText()
Dim page As PdfImportedPage = writer.GetImportedPage(reader, 1)
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 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
End Sub
End Class |