PDFDocument layout not the same in Desktop App and Console App

Hi,

Using Xojo 2021r3.1 on macOS.
I have a class creating a PDF document.

When using this class in a Desktop app everything’s fine.
Using the same class in a Console app the layout is wrong, the page width in console app seems much larger.

PDF is created in the class:

docPDF = new PDFDocument(PDFDocument.PageSizes.A4)

Content is added using g.DrawText

Here’s part of the PDF created in desktop app:

Same part of the PDF created in console app:

t
How can I fix this ?

Thanks !

EDIT: tracing the PDG Graphics, they have the same Width (595) and Height (842) in both desktop and console apps. Fonts are the same (ArialMT and Arial_BoldMT). Document size is different.

Hi @Olivier_Colard

If the apps (Desktop / Console) are running from the same computer with the specified fonts installed on it, it could be a problem of getting the text width of the text under the Console app. We are using different libraries to handle graphics stuff under Web/Console and Desktop, so they throw different values when handling fonts.

It would be good if you can send over the project (privately) or even a reduced example project showing the problem at hand.

Thank you!

Hi @Javier_Menendez,

I prepared a small project showing the problem.
You can get it here: https://gate61.com/xojo_docs/bugPDF.zip

I think I found the problem.
I’m using Graphics extensions to align text right (or centered).
In console app, Graphics.TextWidth always returns 0.

Here is a sample function

Public Sub drawTextRight(Extends g As Graphics, textString As String, xRight As Double, y As Double, wrapWidth As Double = 0, condense As Boolean = False)
  Var strLen As Double = g.TextWidth(textString)
  Var xPos As Double = xRight - strLen
  
  g.DrawText(textString, xPos, y, wrapWidth, condense)
End Sub

Both the printPDF class and the extensions are common to both desktop and console projects.

I hope you have a workaround that can be used in 2021r3.1.

Thanks.