Printing on Windows: can't set margins to 0 in Page Setup dialog

I suspect that this is a Windows problem rather than something that’s happening within Xojo itself, but it’s causing a bit of a headache for one of our customers so I’m hoping that someone on here will know what to do!

To have our app print at the right size and place on the page in Windows with Direct2D, and to match the output from previous versions of Xojo, we need the page setup to have the margins set to zero. For example:

However, we have a customer who isn’t able to do that on his Windows 10 PC: when attempting to set each margin to zero, Windows immediately corrects them to 0.25", 0.25", 0.166", 0.166". The result is that the content that we’re printing is shifted down and to the right.

Can anyone make a good guess as to why this particular customer might not be able to set his page setup margins to zero?

Not going to say that this will solve the problem, but apparently it works for this other piece of software, so maybe it’ll work for yours…

https://techsupport.screenplay.com/hc/en-us/articles/115001515191-Strange-document-issues-on-Windows-10

[quote]Windows, especially Windows 10, occasionally “forgets” printer settings, especially after updates. Screenwriter 6 requires a printer driver (not a physically connected printer) to be added to the system. The reason for this is that printer drivers contain the paper size information, which allows Screenwriter to correctly calculate page length. This can result in all sorts of problems, such as being unable to open documents, unusually long or short pages, weird margins, and potentially crashes.

The solution is to (re)set the default print driver:Open the Windows Control Panel (you can search for it using Cortana, the Windows search feature)
Select Hardware and Sound
Select Devices and Printers
If you see the Microsoft XPS Document Writer there, right-click on it and set that as the default printer. This is Windows’ generic print driver that also happens to support exporting to PDF. Alternatively, select the printer you use and set IT as the default printer. The important point is that a default printer is set.
In Screenwriter, go to File > Print Setup and make sure the Microsoft XPS Document Writer, or your actual printer is selected.
Make sure a default page size is selected, such as Letter or A4.
Press OK.[/quote]

Thanks for the suggestion, but that article seems to be describing a different problem. Am I misunderstanding something?

Sometimes the printer driver itself prevents this because the printer itself cannot print with no margin. It really depends on what kind of printer it is though and whether it does in fact have edge to edge printing.

Most printers cannot (or should not) print right at the edge of the paper… This is evidenced by drivers (such as your example) that reset values to a predetermined minimum…

The print driver/printer you are using will impose a minimum 0.25" margin… and doubtful there is anything you can do about it, since the hardware can’t get any closer to the edge.

Part of the difficulty is that calling the Page Setup dialog defaults the margins to 1" on Windows, and unless the user manually changes them to 0", you’ll be unable to print with smaller margins. If the user changes the margins to 0", then the printer setup returned will have the minimum margins the printer can handle. That gets you as close as you can. The hard part for me is I don’t want to rely on the user making changes to this dialog…:frowning:

I wonder how hard it would be for Xojo to allow changing those options from code.

Thanks for the feedback, folks. Let me try and give a bit more context.

The way that our app prints is to render a PDF from HTML, then read that PDF back and print it. That means that we can use the same PDF for both ‘printing’ as PDF from within our app, and as the source for the ‘real’ printed version, and they look identical.

Previously, Xojo’s default page setup would allow us to read the PDF and then print it at the full page size. If the printer couldn’t actually print to the edge of the page, then that was fine: the user has control over the margins within our app, and could adjust them to work with their printer so that the content wouldn’t be clipped.

What’s changed with the move to Direct2D printing is that Xojo’s default page setup on Windows now has margins of 25mm / 1", and trying to print a full page PDF with these settings results in the content being shifted down and right so that it’s shifted off the page. Setting the page setup margins to zero works around this nicely, and we’ve only found one case where Windows fails to allow a customer to do this.

While the PrinterSetup doesn’t have properties for the page setup margins, I could theoretically read them out of PrinterSetup.SetupString and scale the content to fit. However, I don’t expect the results to look great, and it would mean breaking the currently identical output from our app to either PDF or print.

The Page Setup dialog on Windows doesn’t allow you to select which printer you’re using. How does it know which printer is being used? Is it Windows’ default printer?

Is there any way of programmatically overriding the margins set in an instance PrinterSetup?

Tom, I’m looking at this at the moment, just a quick question do you set MaxHorizontalResolution and MaxVerticalResolution to -1 anywhere in your print process?

Hey Julian, we don’t touch the MaxHorizontalResolution or MaxVerticalResolution properties: we just use what’s provided by the PrinterSetup instance.

Another quick question before I post what I have found, have you tried offsetting your calculations by the PrinterSetup.PageLeft and PrinterSetup.PageTop so you essentially get the position of the corner of the piece of paper? If so, did you find any problems?

Tom, don’t worry about the question above, have a read here and a play with the demo and see if it helps at all.

https://forum.xojo.com/46250-obtaining-the-printer-dpi-in-windows

I think you might be onto something here.

In the tests that I’ve been running, PrinterSetup.PageLeft and PrinterSetup.PageTop aren’t returning helpful values, but Graphics.DrawPicture accepts negative values for its x and y parameters so I might be able to read the margins out of PrinterSetup.SetupString and use them to calculate the offset that will give me identical results to older versions of Xojo. A horrible workaround, but it’s got potential…

You can modify the margins in the setupstring and feed that to the printerSetup
http://documentation.xojo.com/index.php/PrinterSetup.SetupString