Hello,
i want to use the PDFFileWriter in VB.net but it doesn't work.
I have only an empty page. Have you got any examples for VB.NET 2017?
It's a good class.
Thanks
Best regards Frank
What I have tried:
Here is my small testprogram:
Imports PdfFileWriter
Imports System.IO
Imports System.Drawing
Public Class Form1
Dim ArialFont As PdfFont
Dim FontSize As Double
Dim Ascent As Double
Dim Descent As Double
Dim FontHeight2 As Double
Dim Document As PdfDocument
Dim CenterX As Double = 4.25
Dim CenterY As Double = 5.5
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim npfad As String = ""
SaveFileDialog1.Title = "PDF speicher unter..."
SaveFileDialog1.OverwritePrompt = True
If SaveFileDialog1.ShowDialog = DialogResult.OK And SaveFileDialog1.FileName > "" Then
npfad = SaveFileDialog1.FileName
If UCase(npfad).EndsWith("PDF") = False Then
npfad = npfad & ".PDF"
End If
Dim PDFDokument As New PdfDocument(PaperType.A4, False, UnitOfMeasure.Inch, npfad)
Dim FontName1 As String = "Arial"
Dim FontName2 As String = "Times New Roman"
ArialFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Regular, True)
Dim ArialNormal As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Regular, True)
Dim ArialBold As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Bold, True)
Dim ArialItalic As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Italic, True)
Dim ArialBoldItalic As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Bold And FontStyle.Italic, True)
Dim TimesNormal As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName2, FontStyle.Regular, True)
Dim PDFPage As New PdfPage(PDFDokument)
Dim Contents As New PdfContents(PDFDokument)
Dim left As Double = CenterX - 0.5 * 1
Dim Right As Double = CenterX + 0.5 * 1
Dim Top As Double = CenterY + 0.5 * 1
Dim Bottom As Double = CenterY - 0.5 * 1
Contents.DrawText(ArialFont, 10, 10, 10, TextJustify.Center, DrawStyle.Normal, Color.Black, "Hallo")
Contents.SaveGraphicsState()
Contents.SetLineWidth(0.1)
Contents.SetColorStroking(Color.Black)
Contents.SetColorNonStroking(Color.LightBlue)
Contents.DrawRectangle(left, Bottom, 3, 3, PaintOp.CloseFillStroke)
Contents.RestoreGraphicsState()
Dim nText As String = "Hallo Welt"
Dim Breite As Double = ArialBold.TextWidth(25, nText)
Dim Höhe As Double = ArialBold.LineSpacing(25)
Contents.SaveGraphicsState()
Dim nBarcode As New Barcode128("2018-2928282")
Contents.SetColorNonStroking(Color.Red)
Contents.DrawBarcode(3, 7, 0.01, 1, nBarcode, ArialNormal, 8)
Contents.SetLineWidth(0.01)
Contents.BeginTextMode()
Contents.SetColorStroking(Color.DarkBlue)
Contents.DrawText(ArialBold, 25, 4, 9, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 0, 255), Color.FromArgb(255, 255, 0, 0), "Hallo Frank")
Contents.DrawLine(10, 10, 50, 20)
Contents.EndTextMode()
Contents.DrawRectangle(1, 1, 6, 9, PaintOp.CloseFillStroke)
Contents.RestoreGraphicsState()
PDFDokument.CreateFile()
Process.Start(npfad)
End If
End Sub
End Class