Cross platform printing

Hi,
as the object says i’m trying (without success) to code a function in Xojo 2017r3 so that my program can print an invoice who look the same on Windows and Mac.
After hours and hours of trying i still don’t understand how i can achive that result.
I’m coding on OS X 10.13.3 and Xojo 2017r3 but i need to compile my app for a customer who only has Windows 7/10.
When i debug my app on my mac it looks like it should but when i compile it and run on a demo pc i have here in the office the print is smaller and out of position even if i’m printing on the same printer.
I read on the forum something about dpi but it is a little above my skill … could please someone help me in a more easy to understand way ?

What i do is something like that :

Dim ps As New PrinterSetup Dim invoice as New Graphics ps.MaxHorizontalResolution = -1 ps.MaxVerticalResolution = -1 invoice = OpenPrinterDialog(ps)

after that i do some Drawstring, PenHeight DrawRoundRect etc … just to place things where i want them to be.

is there a way to print so that the layout is the same in Windows and Mac ?

Thanks
Mattia

Use the same font ?

What did you get different ?

is not a font problem.
i have left and upper margin wrong. the size of a box is different. If i set the “correct” size for a box on mac is smaller in Windows. If i set it for windows when i print on the mac is bigger and so it goes out of the page

You have full control on margins, so set them your way.

How do you set the size of the box ?

Same Printer / Printer software ?

Can you print to pdf and check if the printing is the same or <> ?

Resolution to -1: can ypu get the real number (or set it to 300 for each platform and check what is printed ?

Care to add code used to print a string (or two) and a box: I have a Windows (current) and macOS (what is your used version ?)

If you do not want to hear about DPI just yet

create a variable

dim dfFactor as double if TargetWin32 then dfFactor = 96/72 else dfFactor = 1 end if

Multiply all your sizes by dfFactor

g.drawrect 10* dfFactor, 20 * dfFactor, 200 * dfFactor, 200 * dfFactor

This is not ‘the best’ solution but it will probably do well enough for you until you are ready to look at it in more detail

Changed to:

dim dfFactor as double if TargetWin32 then dfFactor = 96/72 else dfFactor = 1 end if

Otherwise dfFactor was 0.00 on a Mac

[quote=373517:@Jeff Tullin]If you do not want to hear about DPI just yet

create a variable

dim dfFactor as double if TargetWin32 then dfFactor = 96/72

Multiply all your sizes by dfFactor

g.drawrect 10* dfFactor, 20 * dfFactor, 200 * dfFactor, 200 * dfFactor

This is not ‘the best’ solution but it will probably do well enough for you until you are ready to look at it in more detail[/quote]

Hi Jeff,
thank you for your answer. Using your solution it works ! Thanks!

Suppose i’m ready to hear about DPI … is there a more elegant way to create a universal printing module ?

Thanks again
Mattia

shouldn’t this be

dim dfFactor as double
#if TargetWindows then 
dfFactor = 96/72
#else
dfFactor = 1
#en if

or even

#if TargetWindows then 
const dfFactor as double= 96/72
#else
const dfFactor as double = 1
#endif

[quote=373538:@Dave S]shouldn’t this be

dim dfFactor as double
#if TargetWindows then 
dfFactor = 96/72
#else
dfFactor = 1
#en if

or even

#if TargetWindows then const dfFactor as double= 96/72 #else const dfFactor as double = 1 #endif [/quote]

I figured that out by myself :slight_smile:
I’m now more interested in the dpi thing …

Yep.
Changed it 6 mins before you asked… :slight_smile:

Left to the basics, Mac will give you a page of dots expressed in 72 dots per inch.
An 8 inch wide paper will be 8 * 72 dots across

Direct2D versions of Xojo on Windows, the page size is expressed in 96 dpi
An 8 inch wide paper will have 8 * 96 dots, which is why things print smaller

On both, a 2 inch square is 2 * (dpi) dots

If you ask for a higher resolution, you may get a page at 300 , 150, 600 , 360 dots per inch
Same rules apply
A 2 inch square at 360dpi is 720 dots across.

One common way to handle this variation is to design your code around a known page size , assuming 72 dpi, and use the multiplier to get the ‘right’ number of dots.

eg if your resolution comes in at 300, that dfFactor would be 300/72

PDF resolves this by always being 72dpi but by using doubles as co-ordinates.
There is ‘less than 1 pixel’ resolution in a PDF.