I’ve started to work on a print feature of an app I’m developing.
When I use ‘g = OpenPrinterDialog(Nil, mainWindow)’ the dialog displays but the look of it is a bit different from Safari for example.
Safaris dialog has the PageSize properties and stuff I only get from the PageSetupDialog.
Is there a way to get the same print dialog as Safari from a Xojo app?
This way I could skip the PageSetupDialog as it would not be necessary
PS. I’m on 2013r33.
That depends on how you implement it.
If you have a Cocoa app with a document, the NSDocument class provides a preview in print dialog.
As OpenPrinter function in Xojo doesn’t do that, you see a dummy page with a one.
But I was more looking at the Page Size, Page Orientation and Scale settings in the Safari dialog.
You think I can get them to show in the OpenPrinterDialog? The preview isn’t that important to me
That is page setup dialog.
You get it by using PageSetupDialog function on PrinterSetup class.
[quote=273555:@Christian Schmitz]That is page setup dialog.
You get it by using PageSetupDialog function on PrinterSetup class.[/quote]
My goal here is NOT to use the PrinterSetupDialog. Safari doesn’t have one as these settings are in the OpenPrinterDialog instead.
If I’m not misunderstanding something here
Safari probably uses NSView view printing, which can be done from Xojo, just is not that easy.
That’s the “Print Dialog” with the “Page Setup” options embedded, which makes it super convenient for users.
We used it in our Greetings Card software “Cardsmith” http://www.ohanaware.com/cards/
I wrote a quick tutorial in an issue of xDev mag, but the complete process requires considerable amounts of work. Because the NSView printing uses the drawRect event from the NSView, it’s possible to use Xojo functions to print, however if your printing is a little bit more complicated, you’ll have to use pure Core Graphics.
I was hoping to write a full blown tutorial for xDev mag, but the requirement of CG held it back, as it would require most people to re-write their entire print solution, just for this dialog.
You can also inject views into the dialog, like in our example we’ve inject a view that allows the user to set some print options.
I guess I’ll just stick with both dialogs then as it seems to be a bit more work than I’m willing to put into it right now.
Have a great day guys!
You can use NSPrintOperationMBS. We have that in our plugins.
Thank you Christian. Maybe I’ll look into it in the future
I looked through your site and through the MBS examples but there seem to be no practical example about how one would use that plugin to create a printerSetup and the graphics object to print to.
Basically, what would be required to obtain the same as the picture Sam posted ?
the way cocoa paints is to have a view draw itself on the page.
So you would use maybe a Canvas and run the NSPrintOperationMBS on it’s NSViewMBS.
I didn’t try it, but if needed I can check that the next days. Email me.
OK. I will get to that later and email if I cannot get this sorted. Thanks.
This should be interesting… I could probably extract a demo project over the weekend; but you’d need to convert your drawing commands over to CG to get the benefit (at least from my experience).
Core Graphics is resolution less, so if you draw to a bitmap and then to Core Graphics you’ll lose resolution when printing.
xDev mag 12.3 “Pretty Print Dialog”, will give you a taste. However what you can print is really really limited.
If this involves rewriting everything, I guess I will pass
I think it may not be worth.
Of course if you write a PDF first, you can use PDFKit’s printing to get such a dialog, I think.
You can do some basic printing (as the article demonstrates), but for our card program it had to be converted to CG. For some bizarre reason Xojo doesn’t quite align correctly while CG did, at least that’s what I recall.
It was a lot of hassle; I rather stupidly thought that if I tried my hardest to make a great Mac application; Apple might promote it, as opposed to the clone apps written in QT which look like bad Windows apps. Turns out I’m wrong, Apple quite likes fat apps written in QT that look like something from Windows 3.11 days, especially when they don’t even do Retina properly.
Maybe this is the “Goat Simulator” phenomena ?
Goat Simulator is fun though…
Hi Christian, I’ve tried NSPrintOperation.xojo_binary_project in plugins MBS 164 examples, but the Print Dialog doesn’t show the orientation choice (portrait/landscape)
Is there a way ?