Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Printing/Print to PDF


Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS MacCocoa Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Printing/Print to PDF

This example is the version from Mon, 22th Nov 2015.

Project "Print to PDF.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() // print to PDF in Xojo Cocoa app // change print info to go to dim s as NSPrintInfoMBS = NSPrintInfoMBS.sharedPrintInfo dim d as MemoryBlock = s.data // save old s.SetSaveDestination SpecialFolder.Desktop.Child("test.pdf") // now print something dim g as Graphics = OpenPrinter if g<>Nil then g.DrawString "Hello World PDF", 20, 20 end if s.data = d // restore original settings // now print something to regular printer g = OpenPrinter if g<>Nil then g.DrawString "Hello World Printer", 20, 20 end if End EventHandler
End Control
EventHandler Sub Open() if not TargetCocoa then MsgBox "Please run on Mac with Cocoa target." end if End EventHandler
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...