Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/Print PDF with CoreGraphics/Print PDF with CoreGraphics
Required plugins for this example: MBS MacCG Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/Print PDF with CoreGraphics/Print PDF with CoreGraphics
This example is the version from Thu, 13th Mar 2013.
Project "Print PDF with CoreGraphics.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim f as FolderItem = GetOpenFolderItem(FileTypes1.Pdf) if F = nil then Return // Print PDF on Mac dim pdf as CGPDFDocumentMBS = f.OpenAsCGPDFDocumentMBS if pdf = nil then MsgBox "Failed to read the PDF." Return end if dim g as Graphics = OpenPrinterDialog if g = nil then Return dim PageCount as integer = pdf.PageCount for page as integer = 1 to PageCount dim r as CGRectMBS = pdf.MediaBox(page) dim c as CGContextMBS dim h as integer = g.Handle(g.HandleTypeCGContextRef) if h <> 0 then c = CGContextMBS.contextWithCGContext(h) end if if c = nil then h = g.Handle(g.HandleTypeCGrafPtr) c = CGContextMBS.contextWithCGraf(h) end if if c = nil then // failed to get CGContext for printer break end if c.SaveGState // rotate by 90°? if r.Width > r.Height then const pi = 3.14159265 c.RotateCTM pi*1.5+pi // fix origin c.TranslateCTM 0, -r.Height end if c.DrawCGPDFDocument pdf, r, page // cleanup c.RestoreGState c = nil // important, clean up! if page < PageCount then g.NextPage end if next End EventHandler
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Filetype application/pdf
End FileTypes1
End Project

Feedback, Comments & Corrections

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

MBS Xojo Chart Plugins