Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Apr 02, 2018 2:41 pm

I recently purchased Spire.PDF Version 4.3.0. I am having trouble with the basics.
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

mmieher
 
Posts: 2
Joined: Mon Apr 02, 2018 2:03 pm

Tue Apr 03, 2018 3:34 am

Hello,

Thanks for your feedback. Please change the pen size(such as 0.5) to adjust the performance. You could also change the font size(a bigger size) to improve it when using a pen with large size.
Code: Select all
Dim pen As New PdfPen(Color.Black, 0.5)
Dim font As New PdfFont(pdfFontFace, 15, pdfFontStyle)


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Tue Apr 03, 2018 4:12 pm

That did it! Thank you.

mmieher
 
Posts: 2
Joined: Mon Apr 02, 2018 2:03 pm

Wed Apr 04, 2018 1:41 am

Hello,

Glad to hear that it worked. Welcome to contact us if there is any other question.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.Doc