Platforms to show: All Mac Windows Linux Cross-Platform
/MacCG/Carbon Print Manager/sample with sheets
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 with sheets
This example is the version from Thu, 6th Apr 2016.
Project "sample with sheets.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()
File=FindFile("sample.pdf")
if file.Exists then
thePdfDocument = file.OpenAsCGPDFDocumentMBS
if thePdfDocument=nil then Return
thePrintSession = New MyCPMPrintSessionMBS
if thePrintSession=nil then Return
if thePrintSession.Handle=0 then Return
thePageFormat = NewCPMPageFormatMBS
if thePageFormat=nil then Return
thePrintSettings = NewCPMPrintSettingsMBS
if thePrintSettings=nil then Return
thePrintSession.DefaultPageFormat thePageFormat
thePrintSession.DefaultPrintSettings thePrintSettings
thePrintSession.UseSheets self
'if not thePrintSession.PageSetupDialog(thePageFormat) then return
if not thePrintSession.PrintDialog(thePrintSettings,thePageFormat) then return
end if
End EventHandler
End Control
EventHandler Sub Open()
self.Left=200
End EventHandler
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
Sub SheetDone()
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
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 Sub
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
Property file As FolderItem
Property thePageFormat As CPMPageFormatMBS
Property thePdfDocument As CGPDFDocumentMBS
Property thePrintSession As CPMPrintSessionMBS
Property thePrintSettings As CPMPrintSettingsMBS
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
Class MyCPMPrintSessionMBS Inherits CPMPrintSessionMBS
EventHandler Sub SheetDone(WindowHandle as integer, accepted as boolean)
if accepted then
window1.SheetDone
end if
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacCG Plugin.