The quality of output text in the PDF document is awful. I have searched this forum and the web and cannot find an answer.
Attached is a screen print from Acrobat DC Reader.
Not sure what I am doing wrong.
Here is my code:
- Code: Select all
' PDF Creation ----------------------------------------------
Public pdfDoc As New PdfDocument
Public pdfPage As PdfPageBase
Public pdfMargin As New PdfMargins
Public Cvtr As New PdfUnitConvertor()
Public pdfFontSize As Integer
Public pdfFontFace As PdfFontFamily
Public pdfFontStyle As PdfFontStyle
Public Function CreateWOAPDF(inWO As Integer) As String
Dim tFileName As String = "c:\install\WOA-" & inWO & ".pdf"
' Confused why I have to set to 100. Setting to anything less I see nothing
pdfMargin.Top = Cvtr.ConvertUnits(100, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Bottom = pdfMargin.Top
pdfMargin.Top = pdfMargin.Top
pdfMargin.Left = pdfMargin.Top
PrintWOAHeader(inWO)
pdfDoc.PrintDocument.Print()
' Save Document and Clone for Margin Set --------------------------------------------------------------------
' The following exercise is apparently necessary to change the default enormous margins
pdfDoc.SaveToFile(tFileName, FileFormat.PDF)
pdfDoc.Close()
Dim doc As New PdfDocument
doc.LoadFromFile(tFileName)
Dim newDoc As New PdfDocument
For Each page As PdfPageBase In doc.Pages
Dim newPage As PdfPageBase = newDoc.Pages.Add(page.Size, New PdfMargins(0))
newPage.Canvas.ScaleTransform(page.ActualSize.Width / (page.ActualSize.Width - pdfMargin.Left() - pdfMargin.Right()),
page.ActualSize.Height / (page.ActualSize.Height - pdfMargin.Top - pdfMargin.Bottom))
newPage.Canvas.DrawTemplate(page.CreateTemplate(), New PointF(-pdfMargin.Left(), -pdfMargin.Top))
Next
newDoc.SaveToFile(tFileName, FileFormat.PDF)
Return tFileName
End Function
Public Sub PrintWOAHeader(inWO As String)
pdfPage = pdfDoc.Pages.Add()
pdfFontSize = 10
pdfFontFace = PdfFontFamily.Helvetica
pdfFontStyle = PdfFontStyle.Regular
Outprint(pdfPage, "Test", 0, 0)
End Sub
Public Sub Outprint(ByVal inPage As PdfPageBase, ByVal inData As String, ByVal StartX As Integer, ByVal StartY As Integer)
Dim state As PdfGraphicsState = inPage.Canvas.Save()
' the Plus 50 part is a mystery as well
Dim pdfX As Integer = Cvtr.ConvertUnits(StartX + 50, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
Dim pdfY As Integer = Cvtr.ConvertUnits(StartY + 50, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
Dim tPoint As New Point(pdfX, pdfY)
Dim pen As New PdfPen(Color.Black, 1)
Dim brush As PdfBrush = PdfBrushes.Black
Dim format As New PdfStringFormat(PdfTextAlignment.Left)
Dim font As New PdfFont(pdfFontFace, pdfFontSize, pdfFontStyle)
inPage.Canvas.DrawString(inData, font, pen, brush, pdfX, pdfY, format)
inPage.Canvas.Restore(state)
End Sub