Example: /MacCG/Print PDF with CoreGraphics/Print PDF with CoreGraphics

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

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, MBS MacCF 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 Tue, 21th Jan 2019.

Project "Print PDF with CoreGraphics.xojo_binary_project"
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 // 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
FileTypes1
Filetype application/pdf
End FileTypes1
End Project

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


💬 Ask a question or report a problem