Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/Carbon Print Manager/sample


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/sample

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

Project "sample.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action() Dim File As FolderItem dim thePrintSession as CPMPrintSessionMBS dim thePageFormat as CPMPageFormatMBS dim thePrintSettings as CPMPrintSettingsMBS dim thePdfDocument as CGPDFDocumentMBS dim LastPage as Integer dim AdjustedPageSize as CPMRectMBS dim AdjustedPaperSize as CPMRectMBS dim UnadjustedPageSize as CPMRectMBS dim UnadjustedPaperSize as CPMRectMBS dim DrawRect as CGRectMBS dim thePrintContext as CGContextMBS dim TrimBox as CGRectMBS dim cropbox as CGRectMBS File=FindFile("sample.pdf") if file.Exists then thePdfDocument = file.OpenAsCGPDFDocumentMBS if thePdfDocument=nil then Return thePrintSession = NewCPMPrintSessionMBS if thePrintSession=nil then Return thePageFormat = NewCPMPageFormatMBS if thePageFormat=nil then Return thePrintSettings = NewCPMPrintSettingsMBS if thePrintSettings=nil then Return thePrintSession.DefaultPageFormat thePageFormat thePrintSession.DefaultPrintSettings thePrintSettings 'if not thePrintSession.PageSetupDialog(thePageFormat) then return if not thePrintSession.PrintDialog(thePrintSettings,thePageFormat) then return LastPage = thePdfDocument.PageCount if thePrintSettings.LastPage<lastpage then lastpage=thePrintSettings.LastPage end if thePrintSettings.LastPage=lastpage thePrintSession.BeginDocument(thePrintSettings, thePageFormat) for currentCopy as Integer = 1 to thePrintSettings.Copies for currentPage as Integer = thePrintSettings.FirstPage to LastPage cropbox=thePdfDocument.CropBox(currentPage) TrimBox=thePdfDocument.TrimBox(currentPage) thePrintSession.BeginPage(thePageFormat, nil) thePrintContext = thePrintSession.PageContext if thePrintContext = Nil then return AdjustedPageSize=thePageFormat.AdjustedPageSize AdjustedPaperSize=thePageFormat.AdjustedPaperSize UnadjustedPageSize=thePageFormat.UnadjustedPageSize UnadjustedPaperSize=thePageFormat.UnadjustedPaperSize dim s(-1) as string s.append "AdjustedPageSize: "+str(AdjustedPageSize) s.append "AdjustedPaperSize: "+str(AdjustedPaperSize) s.append "UnadjustedPageSize: "+str(UnadjustedPageSize) s.append "UnadjustedPaperSize: "+str(UnadjustedPaperSize) s.append "Cropbox: "+str(Cropbox) s.append "TrimBox: "+str(TrimBox) MsgBox Join(s,EndOfLine) DrawRect =CGMakeRectMBS(UnadjustedPaperSize.left, -(UnadjustedPaperSize.Height-AdjustedPageSize.Height+UnadjustedPaperSize.top), UnadjustedPaperSize.Width, UnadjustedPaperSize.Height) thePrintContext.DrawCGPDFDocument thePdfDocument,DrawRect, currentPage thePrintContext = nil thePrintSession.EndPage next next thePrintSession.EndDocument end if End EventHandler
End Control
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Private Function Str(p as cgrectMBS) As string Return str(p.Left)+" "+str(p.top)+" "+str(p.Width)+" "+str(p.Height) End Function
Private Function Str(p as cpmrectMBS) As string Return str(p.Left)+" "+str(p.top)+" "+str(p.Width)+" "+str(p.Height) End Function
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

See also:

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


The biggest plugin in space...