Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/Carbon Print Manager/Carbon Print Hello


Required plugins for this example: MBS MacCG Plugin, MBS MacCF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/Carbon Print Manager/Carbon Print Hello

This example is the version from Thu, 6th Apr 2016.

Project "Carbon Print Hello.xojo_binary_project"
FileTypes
Filetype application/pdf
End FileTypes
Class Window1 Inherits Window
Control NormalTestButton Inherits PushButton
ControlInstance NormalTestButton Inherits PushButton
EventHandler Sub Action() dim pf as CPMPageFormatMBS dim ps as CPMPrintSessionMBS dim pt as CPMPrintSettingsMBS ps=NewCPMPrintSessionMBS if ps<>Nil then pf=NewCPMPageFormatMBS pt=NewCPMPrintSettingsMBS ps.DefaultPageFormat pf ps.DefaultPrintSettings pt if ps.PageSetupDialog(pf) then if ps.PrintDialog(pt,pf) then draw pf,ps,pt,true end if end if else MsgBox "We need Mac OS X 10.2!" end if End EventHandler
End Control
Control SilentTestButton Inherits PushButton
ControlInstance SilentTestButton Inherits PushButton
EventHandler Sub Action() dim pf as CPMPageFormatMBS dim ps as CPMPrintSessionMBS dim pt as CPMPrintSettingsMBS ps=NewCPMPrintSessionMBS if ps<>Nil then pf=NewCPMPageFormatMBS pt=NewCPMPrintSettingsMBS ps.DefaultPageFormat pf ps.DefaultPrintSettings pt draw pf,ps,pt,false else MsgBox "We need Mac OS X 10.2!" end if End EventHandler
End Control
Control TestPreviewButton Inherits PushButton
ControlInstance TestPreviewButton Inherits PushButton
EventHandler Sub Action() dim pf as CPMPageFormatMBS dim ps as CPMPrintSessionMBS dim pt as CPMPrintSettingsMBS dim f as FolderItem ps=NewCPMPrintSessionMBS if ps<>Nil then pf=NewCPMPageFormatMBS pt=NewCPMPrintSettingsMBS ps.DefaultPageFormat pf ps.DefaultPrintSettings pt f=SpecialFolder.Desktop.Child("Preview.pdf") ps.SetDestination pt,2,"application/pdf",f.URLPath if ps.LastError=0 then draw pf,ps,pt,false f.Launch else MsgBox "no preview? "+str(ps.LastError) end if else MsgBox "We need Mac OS X 10.2!" end if End EventHandler
End Control
Control TestFaxButton Inherits PushButton
ControlInstance TestFaxButton Inherits PushButton
EventHandler Sub Action() dim pf as CPMPageFormatMBS dim ps as CPMPrintSessionMBS dim pt as CPMPrintSettingsMBS ps=NewCPMPrintSessionMBS if ps<>Nil then pf=NewCPMPageFormatMBS pt=NewCPMPrintSettingsMBS ps.DefaultPageFormat pf ps.DefaultPrintSettings pt ps.SetDestination pt,3,"com.apple.documentformat.default", "" if ps.LastError=0 then draw pf,ps,pt,true else MsgBox "no fax? "+str(ps.LastError) end if else MsgBox "We need Mac OS X 10.2!" end if End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control ListBox2 Inherits ListBox
ControlInstance ListBox2 Inherits ListBox
End Control
Control PrintPDFButton Inherits PushButton
ControlInstance PrintPDFButton Inherits PushButton
EventHandler Sub Action() dim f as FolderItem dim pdf as CGPDFDocumentMBS dim pf as CPMPageFormatMBS dim ps as CPMPrintSessionMBS dim pt as CPMPrintSettingsMBS dim pr as CPMRectMBS dim cr as CGRectMBS dim g as CGContextMBS f=GetOpenFolderItem("Application/pdf") if f<>nil then pdf=f.OpenAsCGPDFDocumentMBS if pdf<>nil then ps=NewCPMPrintSessionMBS if ps<>Nil then pf=NewCPMPageFormatMBS pt=NewCPMPrintSettingsMBS ps.DefaultPageFormat pf ps.DefaultPrintSettings pt f=SpecialFolder.Desktop.Child("print to pdf output.pdf") ps.SetDestination pt,2,"application/pdf", f.URLPath ps.BeginDocumentNoDialog pt,pf pr=pf.AdjustedPageSize cr=CGMakeRectMBS(pr.left,pr.top,pr.Width,pr.Height) ps.BeginPageNoDialog pf,pr g=ps.PageContext g.DrawCGPDFDocument pdf,cr,1 g.SelectFont "Helvetica",18,1 g.SetRGBFillColor 0,0,0,1 g.ShowTextAtPoint "The first page of the pdf file.",20,20 g.FillPath g=nil ps.EndPageNoDialog ps.EndDocumentNoDialog f.Launch else MsgBox "We need Mac OS X 10.2!" end if else MsgBox "Can't open PDF file named """+f.name+"""." end if end if End EventHandler
End Control
EventHandler Sub Open() dim ps as CPMPrintSessionMBS dim pc as CPMPrinterMBS dim ar() as string dim i,index,c as integer dim r as CPMResolutionMBS ListBox1.DeleteAllRows ListBox2.DeleteAllRows ps=NewCPMPrintSessionMBS if ps<>nil then ps.CreatePrinterList(ar,index,pc) for each s as string in ar ListBox1.AddRow s if i=index then ListBox1.CellBold(index,0)=true end if next end if if pc<>nil then c=pc.ResolutionCount for i=1 to c r=pc.IndexedPrinterResolution(i) if r<>nil then ListBox2.AddRow str(r.Horizontal)+" x "+str(r.Vertical) end if next end if End EventHandler
Sub Draw(pf as CPMPageFormatMBS, ps as CPMPrintSessionMBS, pt as CPMPrintSettingsMBS, dialog as boolean) dim g as CGContextMBS dim r as CPMRectMBS dim cr as CGRectMBS dim i as integer r=pf.AdjustedPageSize if dialog then ps.BeginDocument(pt,pf) else ps.BeginDocumentNoDialog(pt,pf) end if pt.LastPage=2 for i=1 to 2 if dialog then ps.BeginPage(pf,nil) else ps.BeginPageNoDialog(pf,nil) end if g=ps.PageContext if ps.LastError<>0 then MsgBox "PageContext lasterror: "+str(ps.LastError) end if if g<>Nil then cr=CGMakeRectMBS(0,0,r.width,r.height) g.SetGrayFillColor 0.5,0.5 g.SetGrayStrokeColor 0.5,0.5 g.FillRect cr cr=CGMakeRectMBS(100,100,200,200) g.SetRGBFillColor 1,0,0,0.5 cr.Left=20 cr.Top=10 cr.Width=150 cr.Height=200 g.FillRect cr g.SetRGBFillColor 0,1,0,0.5 cr.Left=120 cr.Top=10 cr.Width=150 cr.Height=200 g.FillRect cr g.SetRGBFillColor 0.0, 0.7, 0.9, 1.0 g.SelectFont "Helvetica", 36.0, 1 g.ShowTextAtPoint "Hello World on page "+str(i),20,r.height/2 g=nil else MsgBox "g is nil!?" end if if dialog then ps.EndPage else ps.EndPageNoDialog end if next if dialog then ps.EndDocument else ps.EndDocumentNoDialog end if End Sub
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

See also:

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


The biggest plugin in space...